home *** CD-ROM | disk | FTP | other *** search
/ Light ROM 1 / LIGHT-ROM 1 (Amiga Library Services)(1994).iso / ffdisks / d895.lha / MuchMore / Src / MuchMore.mod next >
Text File  |  1993-06-27  |  88KB  |  2,715 lines

  1. (*---------------------------------------------------------------------------
  2. :Program.    MuchMore.mod
  3. :Author.     Fridtjof Siebert
  4. :Address.    Nobileweg 67, D-70439 Stuttgart, Germany
  5. :Shortcut.   [fbs]
  6. :Copyright.  Freeware
  7. :Language.   Oberon-2
  8. :Translator. Amiga Oberon Compiler v3.01
  9. :History.   V1.0 summer-88: First very slow internal version             [fbs]
  10. :History.   V1.1 24-Sep-88: First published version                      [fbs]
  11. :History.   V1.2 26-Nov-88: Now displays Filelength & Percentage         [fbs]
  12. :History.        27-Nov-88: Mouse can be used instead of Space/BackSpace [fbs]
  13. :History.   V1.3 29-Apr-89: Strong increase in speed, removed WarpText   [fbs]
  14. :History.        29-Apr-89: Now supports Numeric Keys (Home,PgUp etc.)   [fbs]
  15. :History.        29-Apr-89: Now opens Screen as big as gfx.normalDisplay [fbs]
  16. :History.   V1.4 29/30-Apr-89: Asynchronus loading/displaying. Very nice [fbs]
  17. :History.        30-Apr-89, 00:33: Removed bugs in Filelength & L-Command[fbs]
  18. :History.        30-Apr-89, 02:21: Added Find-Command                    [fbs]
  19. :History.        30-Apr-89, 10:30: Scrolling stops when window inactive  [fbs]
  20. :History.        01-May-89: Allocates no more unneeded memory for text   [fbs]
  21. :History.        07-May-89: Allocates even less memory now               [fbs]
  22. :History.        14-May-89: Removed deadlock-bug with Find-Window        [fbs]
  23. :History.   V1.5 25-May-89: Added print feature                          [fbs]
  24. :History.        25-May-89: Removed all imports (apart from Arts)        [fbs]
  25. :History.        26-May-89: inspired by J. Kupfer, I added nk 5 to quit  [fbs]
  26. :History.        26-May-89: Now handle BS correctly                      [fbs]
  27. :History.   V1.6 02-Jul-89: Now supports several fontstyles and colors   [fbs]
  28. :History.   V1.7 03-Jul-89: Is again as fast as it was with 2 colors     [fbs]
  29. :History.        03-Jul-89: Now no more crashes when quitting while print[fbs]
  30. :History.        07-Jul-89: removed bug with texts of length 0           [fbs]
  31. :History.   V1.8 10-Jul-89: small bug in find-command removed            [fbs]
  32. :History.        10-Jul-89: now found strings are highlighted            [fbs]
  33. :History.        14-Jul-89: nk0 to display fileinfo                      [fbs]
  34. :History.   V2.0 06-Aug-89: Ported this to OBERON                        [fbs]
  35. :History.        06-Aug-89: Added ARP-FileRequester                      [fbs]
  36. :History.        07-Aug-89: Added L - (load new file) Command            [fbs]
  37. :History.   V2.1 03-Sep-89: no more gurus if an r/w error occures        [fbs]
  38. :History.        03-Sep-89: MM used to execute CSI-Codes backwards. fixed[fbs]
  39. :History.        03-Sep-89: ping / pong with Shift+Fn / Fn               [fbs]
  40. :History.        03-Sep-89: new command: goto                            [fbs]
  41. :History.   V2.2 05-Sep-89: will run with any keymapping now             [fbs]
  42. :History.   V2.3 17-Sep-89: New command: sleep & Pop-Up feature          [fbs]
  43. :History.        17-Sep-89: "MuchMore -s" will go to sleep immediately   [fbs]
  44. :History.        17-Sep-89: Interprets <CSI>m as <CSI>0m now             [fbs]
  45. :History.   V2.4 17-Sep-89: New command: write block "w"                 [fbs]
  46. :History.        17-Sep-89: rewritten argument parser to allow quotes    [fbs]
  47. :History.   V2.5 18-Sep-89: now uses the 8x8 font set with SetFont       [fbs]
  48. :History.        19-Sep-89: no more scatters memory. Allocates 4K Chunks [fbs]
  49. :History.   V2.6 26-Jun-90: Made MuchMore reentrant                      [fbs]
  50. :History.        26-Jun-90: Opens 1-Plane Screen if memory is rare       [fbs]
  51. :History.        26-Jun-90: Asynchronus fast scrolling with Ctrl-Up/Down [fbs]
  52. :History.        26-Jun-90: Now supports interlaced screens              [fbs]
  53. :History.        08-Aug-90: CLI-Option '-l' to toggle interlaced mode    [fbs]
  54. :History.   V2.7 09-Aug-90: no more RethinkDisplay()s,looks good with 2.0[fbs]
  55. :History.        10-Aug-90: Supports Kick2.0 ASL-FileRequester           [fbs]
  56. :History.   V2.8 26-Dez-90: Leaves space between lines on interl. scrns  [fbs]
  57. :History.   V3.0 04-Jul-91: Supports any non-proportional font now       [fbs]
  58. :History.        04-Jul-91: no more supports '-s' (sleep),was rarely used[fbs]
  59. :History.        04-Jul-91: new Options -f<font> and -s<size> for font   [fbs]
  60. :History.        09-Nov-91: Find works w/ dmouse(window may get inactive)[fbs]
  61. :History.   V3.1 04-Sep-92: Uses Screenmode of Workbench screen          [fbs]
  62. :History.   V3.2 02-Nov-92: Supports non-scrollable screens              [fbs]
  63. :History.        02-Nov-92: Complete redraw doesn't scroll anymore       [fbs]
  64. :History. V3.2.1 24-Dec-92: XPK Support                                   (cs)
  65. :History.        24-Dec-92: New option -p for Password                    (cs)
  66. :History.        24-Dec-92: New option -e for Extra Spacing               (cs)
  67. :History.        24-Dec-92: New option -c for Screen Colors               (cs)
  68. :History.        24-Dec-92: Tooltypes                                     (cs)
  69. :History. V3.2.2 08-Jan-93: Doesn't use MyMakeScreen() no more            (cs)
  70. :History. V3.2.3 08-Feb-93: Now closes Console Device                     (cs)
  71. :History.        08-Feb-93: Non-Scroll Mode didn't work always            (cs)
  72. :History.        10-Feb-93: ScreenMode Requester                          (cs)
  73. :History.        10-Feb-93: New Option -s for Scroll Mode                 (cs)
  74. :History.        10-Feb-93: Busy Pointer                                  (cs)
  75. :History.        14-Feb-93: Now evals Tooltypes also on CLI start         (cs)
  76. :History. V3.2.4 15-Feb-93: Clears Idcmp while Busy                       (cs)
  77. :History.        15-Feb-93: Bugs in GetString fixed                       (cs)
  78. :History.        19-Feb-93: More Scrollmodes                              (cs)
  79. :History.        20-Feb-93: Bug in Type() fixed                           (cs)
  80. :History. V3.2.5 08-Mar-93: Asynch Scrolling changed                      (cs)
  81. :History.        08-Mar-93: New Option -t for Taskpri                     (cs)
  82. :History.        10-Mar-93: Now uses Dos.ReadArgs if KS 2.04              (cs)
  83. :History. V3.2.6 19-Mar-93: scrollmode 3 now also scrolls soft            (cs)
  84. :History.        19-Mar-93: New Option -o for one plane                   (cs)
  85. :History.        19-Mar-93: New Option -a for tab width                   (cs)
  86. :History.        19-Mar-93: Removed QText                                 (cs)
  87. :History.        21-Mar-93: Opens screen with full overscan width         (cs)
  88. :History.        22-Mar-93: Filename can be on any pos at KS1.3           (cs)
  89. :History.        27-Mar-93: New Option N=NOOSCAN                          (cs)
  90. :History. V3.2.7 07-Apr-93: Dont pokes to bitmap no more                  (cs)
  91. :History. V3.2.8 12-Apr-93: New Option B=PLANES                           (cs)
  92. :History. V3.2.9 12-May-93: Implemented V36 ANSI Codes                    (cs)
  93. :History. 3.2.10 16-May-93: Locale Support                                (cs)
  94. :History.        16-May-93: DispMode-Requester font-sensitive             (cs)
  95. :History.   V3.3 21-Jun-93: Code optimised                                (cs)
  96. :History.        25-Jun-93: Safe quit                                     (cs)
  97. :Contents.   A Soft-Scrolling ASCII-File Printer.
  98. :Remark.     Compile: 'Oberon -[svbcrntz]dma MuchMore'
  99. :Remark.     Link:    'OLink -dma MuchMore'
  100. ---------------------------------------------------------------------------*)
  101.  
  102.  
  103. MODULE MuchMore; (* $StackChk- *)
  104.  
  105. IMPORT con:= Console,
  106.        d  := Dos,
  107.        e  := Exec,
  108.        g  := Graphics,
  109.        gt := GadTools,
  110.        I  := Intuition,
  111.        ie := InputEvent,
  112.        loc:= Locale,
  113.        str:= Strings,
  114.        u  := Utility,
  115.        ol := OberonLib,
  116.        SYS:= SYSTEM;
  117.  
  118. (*-------------------------------------------------------------------------*)
  119.  
  120. CONST
  121.  
  122.   MuchText = "MuchMore 3.3 © 1993 AMOK\o$VER: muchmore 3.3 (27.6.93)";
  123.  
  124.   usage = "Usage: MuchMore [-a#|-b#|-c#{,#}|-e#|-f<name>/#|-l|-p<name>|-s#|-t#|file]\n"
  125.           "\ta = tab width\n"
  126.           "\tb = planes\n"
  127.           "\tc = colors\n"
  128.           "\te = extra spacing\n"
  129.           "\tf = font/size\n"
  130.           "\tl = toggle lace\n"
  131.           "\tp = password\n"
  132.           "\ts = scroll mode\n"
  133.           "\tt = toolpri";
  134.  
  135.  
  136.   MSGOOM        = 0;
  137.   MSGCOS        = 1;
  138.   MSGCOW        = 2;
  139.   MSGCOF        = 3;
  140.   MSGRWERR      = 4;
  141.   MSGRETRYABORT = 5;
  142.   MSGEMPTY      = 6;
  143.   MSGSAVE       = 7;
  144.   MSGUSE        = 8;
  145.   MSGCANCEL     = 9;
  146.   MSGOK         = 10;
  147.   MSGCHOOSESM   = 11;
  148.   MSGINFOFMT    = 12;
  149.   MSGH1         = 13;
  150.   MSGH2         = 14;
  151.   MSGH3         = 15;
  152.   MSGH4         = 16;
  153.   MSGH5         = 17;
  154.   MSGH6         = 18;
  155.   MSGH7         = 19;
  156.   MSGH8         = 20;
  157.   MSGH9         = 21;
  158.   MSGH10        = 22;
  159.   MSGH11        = 23;
  160.   MSGH12        = 24;
  161.   MSGH13        = 25;
  162.   MSGH14        = 26;
  163.   MSGH15        = 27;
  164.   MSGH16        = 28;
  165.   MSGH17        = 29;
  166.   MSGH18        = 30;
  167.   MSGH19        = 31;
  168.   MSGH20        = 32;
  169.   MSGH21        = 33;
  170.   MSGH22        = 34;
  171.  
  172.  
  173.   TYPE
  174.     MSGTYPE = ARRAY 35 OF e.STRPTR;
  175.  
  176.   CONST
  177.  
  178.     MSGS = MSGTYPE(
  179.       SYS.ADR( "Out of memory"      ),
  180.       SYS.ADR( "Can't open screen"  ),
  181.       SYS.ADR( "Can't open window"  ),
  182.       SYS.ADR( "Can't open file"    ),
  183.       SYS.ADR( "Read/Write Error"   ),
  184.       SYS.ADR( "Retry|Abort"        ),
  185.       SYS.ADR( "File empty"         ),
  186.       SYS.ADR( "Save"               ),
  187.       SYS.ADR( "Use"                ),
  188.       SYS.ADR( "Cancel"             ),
  189.       SYS.ADR( " OK "               ),
  190.       SYS.ADR( "Choose Screen Mode:"),
  191.       SYS.ADR( " File: %-30.30s %ld%% (%ld of %ld Bytes) %ld Lines"),
  192.       SYS.ADR( "\x13                \x15  MuchMore 3.3 Commands:  "),
  193.       SYS.ADR( " \x0dSpace\x05,\x0d LMB\x05:         Start / Stop scrolling, Quit at end of file"),
  194.       SYS.ADR( " \x0dBackSpace\x05,\x0d RMB\x05:     Start / Stop scrolling backwards"),
  195.       SYS.ADR( " \x0dUp\x05/\x0dDown\x05:            Move one line \x0dup\x05 or \x0ddown\x05"),
  196.       SYS.ADR( " \x0dShift \x05+\x0d Up\x05/\x0dDn\x05:      Start / Stop quick scrolling \x0dup\x05 or \x0ddown\x05"),
  197.       SYS.ADR( " \x0dControl\x05:            Increase scroll speed"),
  198.       SYS.ADR( " \x0dAlt\x05+\x0dUp\x05/\x0dDn\x05,\x0d PgUp\x05/\x0dDn\x05: Move one page \x0dup\x05 or \x0ddown\x05"),
  199.       SYS.ADR( " \x0dT\x05,\x0d Home \x05/\x0d B\x05,\x0d End\x05:   Goto \x0dt\x05op / \x0db\x05ottom of text"),
  200.       SYS.ADR( " \x0dF\x05,\x0dN\x05,\x0dP\x05:              \x0dF\x05ind string, \x0dN\x05ext, \x0dP\x05revious occurance"),
  201.       SYS.ADR( " \x0dShift \x05+\x0d Fn\x05:         Set textmarker #n to current position"),
  202.       SYS.ADR( " \x0dFn\x05:                 Goto marker #n or set marker #n if it wasn't set yet"),
  203.       SYS.ADR( " \x0dG\x05:                  \x0dG\x05oto line #n"),
  204.       SYS.ADR( " \x0dNK 0\x05:               Display info line"),
  205.       SYS.ADR( " \x0dShift \x05+\x0d Alt \x05+\x0d O\x05:    Create print\x0do\x05ut of the text"),
  206.       SYS.ADR( " \x0dW\x05:                  \x0dW\x05rite block between marker #1 and #2 to file or prt"),
  207.       SYS.ADR( " \x0dL\x05:                  \x0dL\x05oad new text"),
  208.       SYS.ADR( " \x0dHELP\x05,\x0d H\x05:            Show commands"),
  209.       SYS.ADR( " \x0dESC\x05,\x0d Q\x05,\x0d X\x05,\x0d NK 5\x05:\x0d    Q\x05uit"),
  210.       SYS.ADR( "© \x131992 Fridtjof Siebert, Nobileweg 67, D-70439 Stuttgart, Germany"),
  211.       SYS.ADR( "  \x131993 Christian Stiens, Heustiege 2, D-59348 Lüdinghausen, Germany"),
  212.       SYS.ADR( "  \x13Please refer to MuchMore.doc for a detailed copyright notice"),
  213.       SYS.ADR( "  This is another product of the Amiga MODULA & OBERON Klub Stuttgart - \x0d\x13AMOK") );
  214.  
  215.  
  216. CONST (* RawKey Codes: *)
  217.  
  218.   ESC   = 45H;
  219.   UP    = 4CH;
  220.   DOWN  = 4DH;
  221.   SPACE = 40H;
  222.   BS    = 41H;
  223.   CR    = 44H;
  224.   ENTER = 43H;
  225.   HELP  = 5FH;
  226.   NK0   = 0FH;
  227.   NK1   = 1DH;
  228.   NK2   = 1EH;
  229.   NK3   = 1FH;
  230.   NK5   = 2EH;
  231.   NK7   = 3DH;
  232.   NK8   = 3EH;
  233.   NK9   = 3FH;
  234.   F1    = 50H;
  235.   F10   = 59H;
  236.  
  237.  
  238. CONST
  239.   w = TRUE;
  240.   f = FALSE;
  241.   MaxLen = 256;
  242.  
  243.   MyIdcmp = LONGSET{I.inactiveWindow,I.activeWindow,I.rawKey,I.mouseButtons};
  244.  
  245. (* Control codes: *)
  246.   plain    = CHR(17);
  247.   italic   = CHR(18);
  248.   bold     = CHR(19);
  249.   boldit   = CHR(20);
  250.   ulineon  = CHR(21);
  251.   ulineoff = CHR(22);
  252.  
  253.   Italic = 0;
  254.   Bold   = 1;
  255.   Ulin   = 2;
  256.   Inv    = 3;
  257.  
  258.  
  259. TYPE
  260.  
  261.   String    = e.STRING;
  262.   StringPtr = e.STRPTR;
  263.   CharPtr   = UNTRACED POINTER TO CHAR;
  264.  
  265.   TextLinePtr = UNTRACED POINTER TO TextLine;
  266.   TextLine = STRUCT
  267.                prev,
  268.                next : TextLinePtr;
  269.                len  : INTEGER;
  270.                size : INTEGER;
  271.                text : String;
  272.              END;
  273.  
  274. TYPE
  275.   FileRequesterPtr = UNTRACED POINTER TO FileRequester;
  276.   FileRequester = STRUCT
  277.                     hail      : StringPtr;
  278.                     ddef      : StringPtr;
  279.                     ddir      : StringPtr;
  280.                     wind      : I.WindowPtr;
  281.                     funcFlags : SHORTSET;
  282.                     flags2    : SHORTSET;
  283.                     function  : PROCEDURE;
  284.                     reserved2 : LONGINT;
  285.                   END;
  286.  
  287.   WBStartupPtr = UNTRACED POINTER TO STRUCT (message : e.Message)
  288.                    process    : d.ProcessId;
  289.                    segment    : e.BPTR;
  290.                    numArgs    : LONGINT;
  291.                    toolWindow : StringPtr;
  292.                    argList : UNTRACED POINTER TO ARRAY 256 OF STRUCT
  293.                                  lock : d.FileLockPtr;
  294.                                  name : StringPtr;
  295.                              END;
  296.                  END;
  297.  
  298.   DiskObjectPtr = UNTRACED POINTER TO STRUCT
  299.                     magic      : INTEGER;
  300.                     version    : INTEGER;
  301.                     gadget     : I.Gadget;
  302.                     type       : SHORTINT;
  303.                     defaultTool: StringPtr;
  304.                     toolTypes  : e.APTR;
  305.                     currentX   : LONGINT;
  306.                     currentY   : LONGINT;
  307.                     drawerData : e.APTR;
  308.                     toolWindow : StringPtr;
  309.                     stackSize  : LONGINT;
  310.                   END;
  311.  
  312.   LongPtr = UNTRACED POINTER TO LONGINT;
  313.  
  314.   Args = STRUCT
  315.            a : LongPtr;
  316.            b : LongPtr;
  317.            c : StringPtr;
  318.            d : StringPtr;
  319.            e : LongPtr;
  320.            f : StringPtr;
  321.            n : StringPtr;
  322.            p : StringPtr;
  323.            s : LongPtr;
  324.            t : LongPtr;
  325.            file : StringPtr;
  326.          END;
  327.  
  328. VAR
  329.   pub            : I.ScreenPtr;        (* default public screen             *)
  330.   Screen         : I.ScreenPtr;        (* Screen that contains the Text     *)
  331.   rp             : g.RastPortPtr;      (* Screen's RastPort                 *)
  332.   id             : LONGINT;            (* Display ID                        *)
  333.   BM             : g.BitMapPtr;        (* Screen's BitMap                   *)
  334.   Window         : I.WindowPtr;        (* My window                         *)
  335.   catalog        : loc.CatalogPtr;     (* The Catalog                       *)
  336.   win            : I.WindowPtr;        (* window for Find & Goto            *)
  337.   MyFile         : d.FileHandlePtr;    (* For loading Textfile              *)
  338.   MyAttr         : g.TextAttr;         (* The selected Font attributes      *)
  339.   MyFont         : g.TextFontPtr;      (* The selected Font                 *)
  340.   FontName       : String;             (* My Font Name or ""                *)
  341.   FontSize       : INTEGER;            (* My Font Size                      *)
  342.   FirstLine      : TextLinePtr;        (* the topmost Line                  *)
  343.   TopLine        : TextLinePtr;        (* the topmost Line                  *)
  344.   BottomLine     : TextLinePtr;        (* Last Line displayed on Screen     *)
  345.   LoadLine       : TextLinePtr;        (* currently loaded Line             *)
  346.   LastLine       : TextLinePtr;        (* Last element of LineList          *)
  347.   Name,OldName   : String;             (* Text's Name                       *)
  348.   option         : String;             (* CLI Option                        *)
  349.   taskpri,oldpri : SHORTINT;           (* Muchmore's Task Priority          *)
  350.   Pens           : String;             (* Screen colors                     *)
  351.   Cols           : ARRAY 4 OF INTEGER; (* Color array for LoadRGB4          *)
  352.   icon           : DiskObjectPtr;      (* info                              *)
  353.   nameptr        : StringPtr;          (* String Pointer                    *)
  354.   chptr          : CharPtr;            (* Char Pointer                      *)
  355.   PStr           : String;             (* The command for Dos.Execute       *)
  356.   Buffer         : ARRAY 512 OF CHAR;  (* Buffer for Reading                *)
  357.   RQPos          : LONGINT;            (* Position within ReadBuffer        *)
  358.   RQLen          : LONGINT;            (* Number of CHARs in Buffer         *)
  359.   scrollmode     : INTEGER;            (* 0=MakeScreen/MrgCop 1=ScrollVPort *)
  360.   NumLines       : INTEGER;            (* Number of Lines on Screen         *)
  361.   fontWidth,fontHeight: INTEGER;       (* Font size                         *)
  362.   fontBaseLine   : INTEGER;            (* Font base line                    *)
  363.   spacing        : INTEGER;            (* Extra Line Spacing                *)
  364.   NumColumns     : INTEGER;            (* Number of Columns on Screen       *)
  365.   PageHeight     : INTEGER;            (* fontHeight*NumLines               *)
  366.   AnzLines       : LONGINT;            (* Length of Text in Lines           *)
  367.   MyLock,OldDir  : d.FileLockPtr;      (* To Examine and Load File          *)
  368.   oldcd          : d.FileLockPtr;      (* To save old CD                    *)
  369.   FileInfo       : d.FileInfoBlock;    (* to get File's length              *)
  370.   FileLength,TextLength: LONGINT;      (* Length of File and Displayed Text *)
  371.   ScreenPos      : INTEGER;            (* actual position within bitmap     *)
  372.   ShowTask       : e.Task;             (* the task that displays the text   *)
  373.   ShowStack      : ARRAY 1024 OF LONGINT; (* it's stack                     *)
  374.   numColors      : INTEGER;            (* Number of Colors                  *)
  375.   ShowTaskRunning: BOOLEAN;            (* is Showtask activated?            *)
  376.   SignalNewData  : BOOLEAN;            (* Signal when new data is loaded    *)
  377.   SignalAllRead  : BOOLEAN;            (* send signal at end of text        *)
  378.   Done           : BOOLEAN;            (* Quit                              *)
  379.   print          : BOOLEAN;            (* print text                        *)
  380.   NewText        : BOOLEAN;            (* load new text                     *)
  381.   Info           : BOOLEAN;            (* is info currently displayed ?     *)
  382.   modeReq        : BOOLEAN;            (* Show Display Mode Requester?      *)
  383.   Scroll         : BOOLEAN;            (* scrolling or waiting?             *)
  384.   Fast           : BOOLEAN;            (* scroll quick?                     *)
  385.   Sync           : BOOLEAN;            (* scroll very quick?                *)
  386.   lace,oldLace   : BOOLEAN;            (* use interlaced screen?            *)
  387.   Decrunched     : BOOLEAN;            (* Is file decrunched?               *)
  388.   Scrollable     : BOOLEAN;            (* is screen able to scroll?         *)
  389.   noOscan        : BOOLEAN;            (* Open Text-overscan Screen?        *)
  390.   refresh        : BOOLEAN;            (* Refresh Window?                   *)
  391.   overscanTag    : LONGINT;            (* overscan tag                      *)
  392.   mySigBit       : INTEGER;            (* My SignalBit                      *)
  393.   mySig          : LONGSET;            (* My SignalSet = LONGSET{mySigBit}  *)
  394.   Me             : d.ProcessPtr;       (* my main task                      *)
  395.   MyMsgPtr       : I.IntuiMessagePtr;  (* for receiving Messages            *)
  396.   i,j            : INTEGER;            (* count                             *)
  397.   frame          : INTEGER;            (* Frame Count                       *)
  398.   in,out         : d.FileHandlePtr;    (* i/o for TYPE xxx TO PRT:          *)
  399.   fg,bg          : INTEGER;            (* Text colors                       *)
  400.   oldfg,oldbg    : INTEGER;            (* Old Text colors                   *)
  401.   style          : SHORTSET;           (* Text style                        *)
  402.   CommLine       : UNTRACED POINTER TO ARRAY 1000 OF CHAR;(* The CLI-comands*)
  403.   tabw           : INTEGER;            (* Tabulator width                   *)
  404.   rd             : d.RDArgsPtr;        (* For ReadArgs                      *)
  405.   args           : Args;               (* My CLI Args                       *)
  406.   ArgPtr         : StringPtr;          (* to get WBArg                      *)
  407.   wbm            : WBStartupPtr;       (* WBenchMessage                     *)
  408.   ri             : g.RasInfoPtr;       (* Screen's ViewPort's RasInfo       *)
  409.   NuScreen       : I.NewScreen;        (* to open screen                    *)
  410.   dims           : g.DimensionInfo;    (* Dims for KS2.0                    *)
  411.   disp           : g.DisplayInfo;      (* DisplayInfo for KS2.0             *)
  412.   NuWindow       : I.NewWindow;        (* to open window                    *)
  413.   Prefs          : I.Preferences;      (* Preferences (need wbLace)         *)
  414.   StrGadget      : I.Gadget;           (* Gadget for Find-Command           *)
  415.   StrInfo        : I.StringInfo;       (* its special info                  *)
  416.   arp            : e.LibraryPtr;       (* ArpBase                           *)
  417.   asl            : e.LibraryPtr;       (* ASL-librarybase                   *)
  418.   diskFontBase   : e.LibraryPtr;       (* DiskFont-LibraryBase              *)
  419.   xpk            : e.LibraryPtr;       (* XpkMaster-Librarybase             *)
  420.   iconBase       : e.LibraryPtr;       (* Icon-Librarybase                  *)
  421.   body,text,ok   : I.IntuiText;        (* IntuiTexts for AutoRequest        *)
  422.   FR             : FileRequester;      (* The Requester                     *)
  423.   Filename       : String;             (* The Filename (without path)       *)
  424.   Dirname        : String;             (* its path                          *)
  425.   Pattern        : ARRAY 80 OF CHAR;   (* The pattern for Filerequester     *)
  426.   Password       : String;             (* Password for encrypted texts      *)
  427.   NewDisp        : BOOLEAN;            (* need to rebuild Display ?         *)
  428.   TextMarkers    : ARRAY 10 OF TextLinePtr; (* Marked Positions in text     *)
  429.   FindLine       : TextLinePtr;        (* Last found line                   *)
  430.   KeyMap         : ARRAY 50H OF CHAR;  (* console's KeyMap                  *)
  431.   wreq           : e.IOStdReq;         (* Console IO-Request                *)
  432.   console        : e.DevicePtr;        (* the console.device                *)
  433.   ievent         : ie.InputEvent;      (* InputEvent to convert keycodes    *)
  434.   WriteName      : String;             (* File to write Block               *)
  435.   savefrom,savesize: LONGINT;          (* How much to save?                 *)
  436.   save           : BOOLEAN;            (* save block                        *)
  437.   buffer         : UNTRACED POINTER TO LONGINT; (* buffer to save file      *)
  438.   c              : CHAR;               (* used by GetTextLine();            *)
  439.   le             : INTEGER;            (* global for speed                  *)
  440.  
  441. (*------  Memory:  ------*)
  442.  
  443. CONST ChunkSize = 16384;          (* size of allocated chunks *)
  444.  
  445. TYPE
  446.   MemChunkPtr = UNTRACED POINTER TO MemChunk;  (* chunklist *)
  447.   MemChunk = STRUCT
  448.                prev: MemChunkPtr;     (* link *)
  449.                data: ARRAY ChunkSize OF SYS.BYTE; (* ChunkSize Bytes of memory *)
  450.              END;
  451.  
  452. VAR
  453.   MemIndex: INTEGER;      (* index in current Chunk *)
  454.   CurChunk: MemChunkPtr;  (* current chunk          *)
  455.  
  456.  
  457. (*-------------------------------------------------------------------------*)
  458.  
  459. (*------  DiskFont Procedure:  ------*)
  460.  
  461. PROCEDURE OpenDiskFont*{diskFontBase,-30}(VAR textAttr{8}: g.TextAttr): g.TextFontPtr;
  462.  
  463.  
  464. (*-------------------------------------------------------------------------*)
  465.  
  466. (*------  Icon Procedures:  ------*)
  467.  
  468. PROCEDURE GetDiskObject {iconBase,- 78}(name{8}        : ARRAY OF CHAR): DiskObjectPtr;
  469. PROCEDURE FreeDiskObject{iconBase,- 90}(diskobj{8}     : DiskObjectPtr);
  470. PROCEDURE FindToolType  {iconBase,- 96}(toolTypes{8}   : e.APTR;
  471.                                         typeName{9}    : ARRAY OF CHAR): StringPtr;
  472. PROCEDURE MatchToolValue{iconBase,-102}(typeString{8}  : ARRAY OF CHAR;
  473.                                         val{9}         : ARRAY OF CHAR): BOOLEAN;
  474.  
  475.  
  476. (*-------------------------------------------------------------------------*)
  477.  
  478.  
  479. PROCEDURE StuffChar; (* $EntryExitCode- *)
  480. BEGIN
  481.   SYS.INLINE(016C0U, 04E75U)
  482. END StuffChar;
  483.  
  484.  
  485. (*-------------------------------------------------------------------------*)
  486.  
  487.  
  488. PROCEDURE LocStr (num: LONGINT): e.STRPTR;
  489. VAR default: e.STRPTR;
  490.  
  491. BEGIN
  492.   default := MSGS[num];
  493.   IF loc.base=NIL THEN RETURN default
  494.                   ELSE RETURN loc.GetCatalogStr(catalog,num,default^) END;
  495. END LocStr;
  496.  
  497.  
  498. (*-----------------------------  Requester:  ------------------------------*)
  499.  
  500.  
  501. PROCEDURE Request(Text: ARRAY OF CHAR); (* $CopyArrays- *)
  502.  
  503. BEGIN
  504.   IF ol.wbStarted THEN
  505.     body.frontPen := 0; body.backPen  := 1;  body.drawMode := g.jam2;
  506.     body.leftEdge := 12; body.topEdge  := 8;
  507.     text := body; ok := body;
  508.     body.iText    := SYS.ADR(MuchText);
  509.     body.nextText := SYS.ADR(text);
  510.     text.iText    := SYS.ADR(Text); text.topEdge := 22;
  511.     ok.leftEdge   := 6; ok.topEdge := 3; ok.iText := LocStr(MSGOK);
  512.     SYS.SETREG(0,I.AutoRequest(NIL,SYS.ADR(body),NIL,SYS.ADR(ok),LONGSET{I.rawKey},LONGSET{},320,65));
  513.   ELSE
  514.     SYS.SETREG(0,d.Write(d.Output(),Text,str.Length(Text)));
  515.     SYS.SETREG(0,d.Write(d.Output(),"\n",1));
  516.   END;
  517.   HALT(d.fail);
  518. END Request;
  519.  
  520.  
  521. PROCEDURE OutOfMemHandler;
  522. VAR es: I.EasyStruct;
  523.  
  524. BEGIN
  525.   IF I.int.libNode.version >= 37 THEN
  526.     es.structSize   := SIZE(I.EasyStruct);
  527.     es.flags        := LONGSET{};
  528.     es.title        := SYS.ADR(MuchText);
  529.     es.textFormat   := LocStr(MSGOOM);
  530.     es.gadgetFormat := LocStr(MSGRETRYABORT);
  531.     IF I.EasyRequest(NIL,SYS.ADR(es),NIL,NIL)=0 THEN
  532.       HALT(d.fail)
  533.     END;
  534.   ELSE
  535.     Request(LocStr(MSGOOM)^);
  536.   END;
  537. END OutOfMemHandler;
  538.  
  539.  
  540. (*-------------------------------------------------------------------------*)
  541.  
  542.  
  543. PROCEDURE AllocLine(sz: INTEGER): TextLinePtr;
  544.  
  545. VAR newchunk: MemChunkPtr;
  546.  
  547. BEGIN
  548.   INC(sz,SIZE(TextLine)-MaxLen); IF ODD(sz) THEN INC(sz) END;
  549.   IF MemIndex+sz<=ChunkSize THEN     (* does mem fit into current chunk ? *)
  550.     INC(MemIndex,sz);                (* increment index in current chunk  *)
  551.   ELSE
  552.     NEW(newchunk);                   (* allocate new chunk                *)
  553.     newchunk.prev := CurChunk;       (* link chunk into list              *)
  554.     CurChunk := newchunk;
  555.     MemIndex := sz;
  556.   END;
  557.   RETURN SYS.ADR(CurChunk.data[MemIndex-sz]);
  558. END AllocLine;
  559.  
  560.  
  561. PROCEDURE DisposeLines();
  562.  
  563. VAR chunk: MemChunkPtr;
  564.  
  565. BEGIN
  566.   WHILE CurChunk#NIL DO
  567.     chunk := CurChunk.prev;
  568.     DISPOSE(CurChunk);
  569.     CurChunk := chunk;
  570.   END;
  571.   MemIndex := ChunkSize;
  572. END DisposeLines;
  573.  
  574.  
  575. (*-------------------------------------------------------------------------*)
  576.  
  577. (* $Debug- *)
  578.  
  579.  
  580. PROCEDURE Busy;
  581.  
  582. (* $DataChip+ *)
  583.  
  584. TYPE Data = ARRAY 36 OF INTEGER;
  585.  
  586. CONST ClockData = Data(
  587.   00000U,00000U,
  588.   00400U,007C0U, 00000U,007C0U, 00100U,00380U, 00000U,007E0U,
  589.   007C0U,01FF8U, 01FF0U,03FECU, 03FF8U,07FDEU, 03FF8U,07FBEU,
  590.   07FFCU,0FF7FU, 07EFCU,0FFFFU, 07FFCU,0FFFFU, 03FF8U,07FFEU,
  591.   03FF8U,07FFEU, 01FF0U,03FFCU, 007C0U,01FF8U, 00000U,007E0U,
  592.   00000U,00000U);
  593.  
  594. BEGIN
  595.   IF Window#NIL THEN
  596.     I.OldModifyIDCMP(Window,MyIdcmp-LONGSET{I.rawKey,I.mouseButtons});
  597.     I.SetPointer(Window,ClockData,16,16,-6,0);
  598.   END;
  599. END Busy;
  600.  
  601.  
  602. PROCEDURE UnBusy;
  603. BEGIN
  604.   IF Window#NIL THEN
  605.     I.ClearPointer(Window);
  606.     I.OldModifyIDCMP(Window,MyIdcmp);
  607.   END;
  608. END UnBusy;
  609.  
  610.  
  611. (*------  Scroll:  ------*)
  612.  
  613. PROCEDURE MakeThink(sync,fast,always: BOOLEAN);
  614. VAR m: INTEGER;
  615.  
  616. BEGIN
  617.   IF Scrollable THEN
  618.     m := 1;
  619.     IF ~always THEN
  620.       IF lace & ~fast THEN m := 2 END;
  621.       IF ~sync THEN INC(m,m*2) END;
  622.     END;
  623.     IF (m=1) OR (frame MOD m=0) THEN
  624.       CASE scrollmode OF
  625.       | 0: I.MakeScreen(Screen);
  626.            e.Forbid; g.MrgCop(I.ViewAddress()); e.Permit;
  627.            g.WaitTOF;
  628.       | 1: g.ScrollVPort(SYS.ADR(Screen.viewPort));
  629.            g.WaitTOF;
  630.       ELSE
  631.            I.MakeScreen(Screen);
  632.            I.RethinkDisplay();
  633.       END;
  634.     END;
  635.     frame := (frame + 1) MOD 16384;
  636.   END;
  637. END MakeThink;
  638.  
  639.  
  640. (*------  Clear Display:  ------*)
  641.  
  642.  
  643. PROCEDURE ClearBitMaps;
  644. VAR i: INTEGER;
  645.  
  646. BEGIN
  647.   g.SetRast(rp,0);
  648.   IF Scrollable THEN
  649.     ri.ryOffset := 0;
  650.     ScreenPos := 0;
  651.     MakeThink(f,f,w);
  652.   END;
  653. END ClearBitMaps;
  654.  
  655. (*-------------------------------------------------------------------------*)
  656.  
  657. (*------  Read one TextLine into a Variable:  ------*)
  658.  
  659.  
  660. PROCEDURE GetTextLine(): TextLinePtr;
  661. (* returns NIL at EOF *)
  662.  
  663. VAR
  664.   l: TextLinePtr;
  665.   sz,wd,i,j: INTEGER;
  666.   txt: ARRAY MaxLen+1 OF CHAR;
  667.   num: ARRAY 10 OF INTEGER;
  668.   newcol: BOOLEAN;
  669.   oldstyle: SHORTSET;
  670.  
  671.   PROCEDURE GetCh();
  672.  
  673.   BEGIN
  674.     IF RQPos=RQLen THEN
  675.       RQLen := d.Read(MyFile,Buffer,SIZE(Buffer));
  676.       IF RQLen<0 THEN Request(LocStr(MSGRWERR)^) END;
  677.       RQPos := 0;
  678.     END;
  679.     IF RQLen=0 THEN c := 0X ELSE
  680.       c := Buffer[RQPos]; IF c=0X THEN c:=1X END;
  681.       INC(RQPos); INC(le);
  682.     END;
  683.   END GetCh;
  684.  
  685. BEGIN
  686.   IF RQLen=0 THEN RETURN NIL END;
  687.   sz := 0; wd := 0; le := 0;
  688.   IF Italic IN style THEN IF Bold IN style THEN txt[sz] := boldit ELSE txt[sz] := italic END; INC(sz)
  689.                      ELSE IF Bold IN style THEN txt[sz] := bold; INC(sz) END                      END;
  690.   IF   Ulin IN style     THEN txt[sz] := ulineon; INC(sz) END;
  691.   IF    Inv IN style     THEN txt[sz] := CHR(fg+4*bg+1); INC(sz)
  692.   ELSIF (fg#1) OR (bg#0) THEN txt[sz] := CHR(bg+4*fg+1); INC(sz) END;
  693.   LOOP
  694.     LOOP
  695.       GetCh;
  696.       IF SYS.VAL(CHAR,SYS.VAL(SHORTSET,c)*SHORTSET{0..6})#1BX THEN EXIT END;
  697.       i := -1;
  698.       REPEAT
  699.         GetCh;
  700.         IF (c>=30X) & (c<=39X) THEN
  701.           INC(i); num[i] := 0;
  702.           REPEAT
  703.             num[i] := 10*num[i]+ORD(c)-ORD(30X); GetCh;
  704.           UNTIL (c<30X) OR (c>39X);
  705.         END;
  706.         c := CAP(c);
  707.       UNTIL (c>=3FX(*"?"*)) & (c<=5AX) OR (c=0X) OR (i=9);
  708.       IF c=4DX THEN
  709.         newcol := f; oldstyle := style; j := 0;
  710.         IF i=-1 THEN i:=0; num[0] := 0 END;
  711.         WHILE (i>=j) & (sz<MaxLen-1) DO
  712.           CASE num[j] OF
  713.           0:  style := SHORTSET{}; fg := 1; bg := 0; newcol := w |
  714.           1:  INCL(style,Bold) |
  715.           2:  fg := 2; newcol := w |
  716.           3:  INCL(style,Italic) |
  717.           4:  INCL(style,Ulin) |
  718.           7:  INCL(style,Inv); newcol := w |
  719.           8:  oldfg:=fg; oldbg:=bg; fg:=0; bg:=0; newcol := w |
  720.  
  721.           22: EXCL(style,Bold); fg := 1; newcol := w |
  722.           23: EXCL(style,Italic) |
  723.           24: EXCL(style,Ulin) |
  724.           27: EXCL(style,Inv); newcol := w |
  725.           28: fg:=oldfg; bg:=oldbg; newcol := w |
  726.  
  727.           30..37: fg := (num[j]-30) MOD numColors; (*IF fg>=numColors THEN fg:=numColors-1 END;*) newcol := w |
  728.           39:     fg := 1; newcol := w |
  729.  
  730.           40..47: bg := (num[j]-40) MOD numColors; (*IF bg>=numColors THEN bg:=numColors-1 END;*) newcol := w |
  731.           49:     bg := 0; newcol := w |
  732.  
  733.           ELSE END;
  734.           INC(j);
  735.         END;
  736.         IF (oldstyle#style) & (sz<MaxLen) THEN
  737.           IF Italic IN style THEN IF Bold IN style THEN txt[sz] := boldit ELSE txt[sz] := italic END;
  738.                              ELSE IF Bold IN style THEN txt[sz] := bold   ELSE txt[sz] := plain  END;
  739.           END;
  740.           INC(sz);
  741.           IF (Ulin IN style) THEN
  742.             IF ~((Ulin IN oldstyle)) & (sz<MaxLen) THEN
  743.               txt[sz] := ulineon;
  744.               INC(sz);
  745.             END;
  746.           ELSE
  747.             IF (Ulin IN oldstyle) & (sz<MaxLen) THEN
  748.               txt[sz] := ulineoff;
  749.               INC(sz);
  750.             END;
  751.           END;
  752.         END;
  753.         IF newcol & (sz<MaxLen) THEN
  754.           IF Inv IN style THEN txt[sz] := CHR(fg+4*bg+1)
  755.                           ELSE txt[sz] := CHR(bg+4*fg+1) END;
  756.           INC(sz);
  757.         END;
  758.       END;   (* IF c="m" THEN *)
  759.     END;   (* LOOP *)
  760.     CASE c OF
  761.      20X.. 7FX:    txt[sz] := c; INC(sz); INC(wd) |
  762.     0A1X..0FFX:    txt[sz] := c; INC(sz); INC(wd) |
  763.     8X: (* BS *)   IF wd>0 THEN DEC(sz); DEC(wd); END |
  764.     9X: (* TAB *)
  765.       REPEAT
  766.         txt[sz] := 20X; INC(sz); INC(wd)
  767.       UNTIL (sz=MaxLen) OR (wd=NumColumns) OR (sz MOD tabw=0) |
  768.     0A0X:                txt[sz] := 20X; INC(sz); INC(wd) |
  769.     0AX,0X,0CX: EXIT |
  770.     ELSE END;
  771.     IF (wd>=NumColumns) OR (sz>=MaxLen) THEN EXIT END;
  772.   END;
  773.   txt[sz] := 0X; INC(sz);
  774.   l := AllocLine(sz);
  775.   l.len := le; l.size:= sz;
  776.   WHILE sz>0 DO DEC(sz); l.text[sz]:=txt[sz] END;
  777.   RETURN l;
  778. END GetTextLine;
  779.  
  780.  
  781. (*------  Write Line to Screen:  ------*)
  782.  
  783.  
  784. PROCEDURE Type(pos: INTEGER; line: TextLinePtr);
  785.  
  786. VAR
  787.   style: SHORTSET;
  788.   front,back: SHORTINT;
  789.   c: CHAR;
  790.   last,i,x,y: INTEGER;
  791.   strPtr: UNTRACED POINTER TO ARRAY 256 OF CHAR;
  792.  
  793. BEGIN
  794.   g.SetDrMd(rp,g.jam2);
  795.   IF Scrollable THEN
  796.     g.SetAPen(rp,0);
  797.     y := pos * fontHeight;
  798.     IF ~refresh THEN g.RectFill(rp,0,y,NuScreen.width-1,y+fontHeight-spacing-1) END;
  799.   END;
  800.   i := 0; x := 0; style := SHORTSET{}; front := 1; back := 0;
  801.   LOOP
  802.     WHILE line.text[i] < " " DO
  803.       c := line.text[i];
  804.       IF c=0X THEN EXIT END;
  805.       CASE c OF
  806.       plain   : style := style - SHORTSET{g.bold,g.italic} |
  807.       italic  : EXCL(style,g.bold); INCL(style,g.italic)   |
  808.       bold    : INCL(style,g.bold); EXCL(style,g.italic)   |
  809.       boldit  : style := style + SHORTSET{g.bold,g.italic} |
  810.       ulineon : INCL(style,g.underlined) |
  811.       ulineoff: EXCL(style,g.underlined) |
  812.       1X..10X : DEC(c);
  813.                 front := SHORT(ORD(c)) DIV 4;
  814.                 back  := SHORT(ORD(c)) MOD 4 |
  815.       ELSE END;
  816.       INC(i);
  817.     END;
  818.     strPtr := SYS.ADR(line.text[i]); last := i;
  819.     REPEAT INC(i) UNTIL line.text[i]<" ";
  820.     SYS.SETREG(0,g.SetSoftStyle(rp,style,-SHORTSET{}));
  821.     g.SetAPen(rp,front);
  822.     g.SetBPen(rp,back);
  823.     g.Move(rp,fontWidth*x,fontHeight*pos+fontBaseLine);
  824.     g.Text(rp,strPtr^,i-last);
  825.     INC(x,i-last);
  826.   END;
  827. END Type;
  828.  
  829.  
  830. PROCEDURE CopyScrollLine(pos: INTEGER);
  831. (* Kopiert die an pos geschriebene Zeile auf den entsprechenden DoubleBuffer-Bereich *)
  832. (*
  833.  * ACHTUNG: Darf nur aufgerufen werden, wenn Scrollable TRUE ist!
  834.  *)
  835.  
  836. VAR
  837.   y,z: INTEGER;
  838.  
  839. BEGIN
  840.   y := pos*fontHeight;
  841.   z := PageHeight;
  842.   IF pos>=NumLines THEN z := -z END;
  843.   SYS.SETREG(0,g.BltBitMap(BM, 0,y, BM, 0,y+z, NuScreen.width,fontHeight, 0C0X, SHORTSET{0..7}, NIL));
  844. END CopyScrollLine;
  845.  
  846.  
  847. (*------  Write String to Screen (as bottom line):  ------*)
  848.  
  849.  
  850. VAR writeText: TextLine;
  851.  
  852. PROCEDURE CopyToWriteText(String: StringPtr);
  853.  
  854. BEGIN
  855.   writeText := FirstLine^;
  856.   i := SHORT(str.Length(String^));
  857.   IF i>=NumColumns THEN i := NumColumns-1 END;
  858.   writeText.text[i+1] := 0X;
  859.   writeText.size := i;
  860.   REPEAT
  861.     writeText.text[i] := String[i];
  862.     DEC(i)
  863.   UNTIL i<0;
  864. END CopyToWriteText;
  865.  
  866.  
  867. (*------  Write String to Screen (at any position):  ------*)
  868.  
  869.  
  870. PROCEDURE TypeTo(VAR text: TextLine; pos: INTEGER);
  871.  
  872. BEGIN
  873.   IF pos<NumLines THEN
  874.     IF ~Scrollable THEN
  875.       Type(pos,SYS.ADR(text));
  876.     ELSE
  877.       INC(pos,ScreenPos);
  878.       Type(pos,SYS.ADR(text));
  879.       CopyScrollLine(pos);
  880.     END;
  881.   END;
  882. END TypeTo;
  883.  
  884.  
  885. (*------  Write String to Screen (at any position):  ------*)
  886.  
  887.  
  888. PROCEDURE WriteTo(String: StringPtr; pos: INTEGER);
  889.  
  890. BEGIN
  891.   CopyToWriteText(String);
  892.   TypeTo(writeText,pos);
  893. END WriteTo;
  894.  
  895.  
  896. (*------  Write Line at Bottom of Text:  ------*)
  897.  
  898.  
  899. PROCEDURE AddBottomLine(Line: TextLinePtr; Fast: BOOLEAN);
  900.  
  901. VAR
  902.   i,j: INTEGER;
  903.   y: INTEGER;
  904.  
  905. BEGIN
  906.   IF ~Scrollable THEN
  907.     g.SetAPen(rp,0); g.SetBPen(rp,0);
  908.     IF Fast THEN
  909.       g.ScrollRaster(rp,0,fontHeight,0,0,NuScreen.width-1,NuScreen.height-1);
  910.       IF Sync THEN g.WaitTOF END;
  911.     ELSE
  912.       i := fontHeight;
  913.       REPEAT
  914.         g.ScrollRaster(rp,0,1,0,0,NuScreen.width-1,NuScreen.height-1);
  915.         IF Sync THEN g.WaitTOF END;
  916.         DEC(i);
  917.       UNTIL i=0;
  918.     END;
  919.     Type(NumLines-1,Line);
  920.   ELSE
  921.     Type(ScreenPos+NumLines,Line);
  922.     y := ScreenPos*fontHeight;
  923.     IF Fast THEN
  924.       INC(ri.ryOffset,fontHeight);
  925.       MakeThink(Sync,w,f);
  926.       SYS.SETREG(0,g.BltBitMap(BM, 0,y+PageHeight, BM, 0,y, NuScreen.width,fontHeight, 0C0X, SHORTSET{0..7}, NIL));
  927.     ELSE
  928.       i := fontHeight;
  929.       REPEAT
  930.         INC(ri.ryOffset);
  931.         MakeThink(Sync,f,f);
  932.         SYS.SETREG(0,g.BltBitMap(BM, 0,y+PageHeight, BM, 0,y, NuScreen.width,1, 0C0X, SHORTSET{0..7}, NIL));
  933.         INC(y);
  934.         DEC(i);
  935.       UNTIL i=0;
  936.     END;
  937.     INC(ScreenPos);
  938.     IF ScreenPos=NumLines THEN
  939.       ScreenPos := 0;
  940.       ri.ryOffset := 0;
  941.     END;
  942.   END;
  943. END AddBottomLine;
  944.  
  945.  
  946. (*------  Check whether BottomLine.next is NIL or not:  ------*)
  947.  
  948.  
  949. PROCEDURE TryBottomnext(): BOOLEAN;
  950. (* returns TRUE if BottomLine.next#NIL END; *)
  951.  
  952. BEGIN
  953.   IF (BottomLine.next=NIL) & (MyFile#NIL) THEN
  954.     SignalNewData := w;
  955.     SYS.SETREG(0,e.Wait(mySig));
  956.     SignalNewData := f;
  957.   END;
  958.   RETURN BottomLine.next#NIL;
  959. END TryBottomnext;
  960.  
  961.  
  962. (*------  Scroll down one Line:  ------*)
  963.  
  964.  
  965. PROCEDURE ScrollDown(Fast: BOOLEAN);
  966.  
  967. BEGIN
  968.   IF TryBottomnext() THEN
  969.     BottomLine := BottomLine.next;
  970.     INC(AnzLines);
  971.     INC(TextLength,BottomLine.len);
  972.   ELSE RETURN END;
  973.   IF AnzLines>=NumLines THEN TopLine := TopLine.next END;
  974.   AddBottomLine(BottomLine,Fast);
  975. END ScrollDown;
  976.  
  977.  
  978. (*------  Scroll Up one Line:  ------*)
  979.  
  980.  
  981. PROCEDURE ScrUp (Fast: BOOLEAN);
  982. VAR
  983.   i,j,y: INTEGER;
  984.  
  985. BEGIN
  986.   IF ~Scrollable THEN
  987.     g.SetAPen(rp,0); g.SetBPen(rp,0);
  988.     IF Fast THEN
  989.       g.ScrollRaster(rp,0,-fontHeight,0,0,NuScreen.width-1,NuScreen.height-1);
  990.       IF Sync THEN g.WaitTOF END;
  991.     ELSE
  992.       i := fontHeight;
  993.       REPEAT
  994.         g.ScrollRaster(rp,0,-1,0,0,NuScreen.width-1,NuScreen.height-1);
  995.         IF Sync THEN g.WaitTOF END;
  996.         DEC(i)
  997.       UNTIL i=0;
  998.     END;
  999.     IF TopLine.prev#NIL THEN Type(0,TopLine.prev) ELSE Type(0,FirstLine) END;
  1000.   ELSE
  1001.     IF ScreenPos=0 THEN
  1002.       ri.ryOffset  := NumLines*fontHeight;
  1003.       ScreenPos := NumLines;
  1004.     END;
  1005.     DEC(ScreenPos);
  1006.     IF TopLine.prev#NIL THEN Type(ScreenPos,TopLine.prev) ELSE Type(ScreenPos,FirstLine) END;
  1007.     y := ScreenPos*fontHeight;
  1008.     IF Fast THEN
  1009.       DEC(ri.ryOffset,fontHeight);
  1010.       MakeThink(Sync,w,f);
  1011.       SYS.SETREG(0,g.BltBitMap(BM, 0,y, BM, 0,y+PageHeight, NuScreen.width,fontHeight , 0C0X, SHORTSET{0..7}, NIL));
  1012.     ELSE
  1013.       INC(y,fontHeight);
  1014.       i := fontHeight;
  1015.       REPEAT
  1016.         DEC(ri.ryOffset);
  1017.         MakeThink(Sync,f,f);
  1018.         DEC(y);
  1019.         SYS.SETREG(0,g.BltBitMap(BM, 0,y, BM, 0,y+PageHeight, NuScreen.width,1, 0C0X, SHORTSET{0..7}, NIL));
  1020.         DEC(i);
  1021.       UNTIL i=0;
  1022.     END;
  1023.   END;
  1024. END ScrUp;
  1025.  
  1026.  
  1027. PROCEDURE ScrollUp(Fast: BOOLEAN);
  1028.  
  1029. BEGIN
  1030.   IF (TopLine.prev#NIL) & (TopLine.prev.prev#NIL) THEN
  1031.     TopLine := TopLine.prev;
  1032.     DEC(TextLength,BottomLine.len);
  1033.     DEC(AnzLines);
  1034.     BottomLine := BottomLine.prev;
  1035.     ScrUp(Fast);
  1036.   END;
  1037. END ScrollUp;
  1038.  
  1039.  
  1040. (*------  Undo last AddBottomLine:  ------*)
  1041.  
  1042.  
  1043. PROCEDURE DelLine(Fast: BOOLEAN);
  1044.  
  1045. BEGIN
  1046.   ScrUp(Fast);
  1047.   Info := f;
  1048. END DelLine;
  1049.  
  1050.  
  1051. (*------  Convert String to Integer:  ------*)
  1052.  
  1053. PROCEDURE StrToInt(str: StringPtr; base: INTEGER): LONGINT;
  1054.  
  1055. VAR
  1056.   i,j: INTEGER;
  1057.   num: LONGINT;
  1058.   ch : CHAR;
  1059.   neg: BOOLEAN;
  1060.  
  1061. BEGIN
  1062.   num := 0; i := 0; neg := f;
  1063.   IF  str^[0] = '-'                   THEN str:=SYS.ADR(str[1]); neg := w END;
  1064.   IF  str^[0] = '$'                   THEN str:=SYS.ADR(str[1]); base:=16 END;
  1065.   IF (str^[0]='0')&(CAP(str^[1])='X') THEN str:=SYS.ADR(str[2]); base:=16 END;
  1066.   LOOP
  1067.     IF i=LEN(str^) THEN EXIT END;
  1068.     ch := CAP(str^[i]);
  1069.     IF ch=0X THEN EXIT END;
  1070.     j := ORD(ch);
  1071.     CASE ch OF
  1072.       "0".."9": DEC(j,ORD('0'))   |
  1073.       "A".."F": DEC(j,ORD('A')-10);
  1074.                 IF base=10 THEN base:=16; i:=-1; j:=0; num:=0 END;
  1075.       ELSE EXIT
  1076.     END;
  1077.     num := num * base + j;
  1078.     INC(i);
  1079.   END;
  1080.   IF neg THEN num := -num END;
  1081.   RETURN num
  1082. END StrToInt;
  1083.  
  1084.  
  1085. (*-------------------------------------------------------------------------*)
  1086.  
  1087.  
  1088. PROCEDURE GetStr(name: StringPtr; VAR str: String);
  1089. VAR i: INTEGER;
  1090. BEGIN
  1091.   i := -1;
  1092.   REPEAT
  1093.     INC(i); str[i] := name^[i]
  1094.   UNTIL (name^[i]=0X) OR (i=LEN(str)-1);
  1095.   str[i] := 0X
  1096. END GetStr;
  1097.  
  1098.  
  1099. (*-------------------------------------------------------------------------*)
  1100.  
  1101.  
  1102. PROCEDURE GetLength(t: TextLinePtr);
  1103.  
  1104. BEGIN
  1105.   TextLength := 0; AnzLines := 0;
  1106.   WHILE t#NIL DO INC(AnzLines); INC(TextLength,t.len); t := t.prev END;
  1107. END GetLength;
  1108.  
  1109.  
  1110. (*-------------------------------------------------------------------------*)
  1111.  
  1112.  
  1113. PROCEDURE NewDisplay;
  1114. (* Zeichnet ab BottomLine neu *)
  1115.  
  1116. VAR
  1117.   i: INTEGER;
  1118.   l: TextLinePtr;
  1119.  
  1120. BEGIN
  1121.   IF ~refresh THEN ClearBitMaps END;
  1122.   l := BottomLine.prev;
  1123.   IF l#NIL THEN BottomLine := l END;
  1124.   l := BottomLine;
  1125.   i := NumLines-1;
  1126.   WHILE (i>0) & TryBottomnext() DO
  1127.     BottomLine := BottomLine.next;
  1128.     DEC(i);
  1129.   END;
  1130.   WHILE (i>0) & (l.prev#NIL) DO
  1131.     l := l.prev;
  1132.     DEC(i);
  1133.   END;
  1134.   TopLine := l.next;
  1135.   WHILE i<NumLines DO
  1136.     BottomLine := l;
  1137.     TypeTo(BottomLine^,i);
  1138.     INC(i);
  1139.     l := l.next;
  1140.   END;
  1141.   GetLength(BottomLine);
  1142.   Scroll := f;
  1143. END NewDisplay;
  1144.  
  1145.  
  1146. (*-------------------------------------------------------------------------*)
  1147.  
  1148.  
  1149. PROCEDURE * ShowProc;
  1150.  
  1151. VAR
  1152.   l: TextLinePtr;
  1153.   Down: BOOLEAN;               (* Scroll-Direction                  *)
  1154.   End: BOOLEAN;                (* Quit next time Space is pressed ? *)
  1155.   i,j,k,m: INTEGER;
  1156.   MyMsg: I.IntuiMessage;       (* contains Message                  *)
  1157.   Shift: BOOLEAN;              (* Shifted Keystroke ?               *)
  1158.   Alt: BOOLEAN;                (* Altered Keystroke ?               *)
  1159.   wasInfo: BOOLEAN;            (* was Info line displayed ?         *)
  1160.   Find,FindStr: ARRAY 80 OF CHAR; (* findstring / capitalized findstring *)
  1161.   Goto: ARRAY 10 OF CHAR;      (* string containing goto line #  *)
  1162.   li: LONGINT;                 (* longint value of line to go to *)
  1163.   flen: INTEGER;               (* length of findstring *)
  1164.   HiText: TextLine;            (* Highlited textline *)
  1165.   OldHiText: TextLinePtr;      (* original, un-hilited text *)
  1166.   found: BOOLEAN;              (* TRUE, if find was successful *)
  1167.   chr: CHAR;                   (* converted keycode *)
  1168.  
  1169.  
  1170.   PROCEDURE WaitAllRead();
  1171.  
  1172.   BEGIN
  1173.     IF MyFile#NIL THEN
  1174.       Busy;
  1175.       SignalAllRead := w;
  1176.       SYS.SETREG(0,e.Wait(mySig));
  1177.       SignalAllRead := f;
  1178.       UnBusy;
  1179.     END;
  1180.   END WaitAllRead;
  1181.  
  1182.  
  1183.   PROCEDURE HiLite(at,len: INTEGER);
  1184.   (* Hilites len chars of BottomLine.text starting at position at *)
  1185.  
  1186.   VAR
  1187.     c: INTEGER;
  1188.     col: CHAR;
  1189.  
  1190.   BEGIN
  1191.     OldHiText := BottomLine; HiText := OldHiText^; BottomLine := SYS.ADR(HiText);
  1192.     IF at+len+2<MaxLen THEN
  1193.       c := 0; col := 5X;
  1194.       WHILE c<at DO
  1195.         IF HiText.text[c]<CHR(17) THEN col := HiText.text[c] END;
  1196.         INC(c);
  1197.       END;
  1198.       HiText.text[at] := CHR(17-ORD(col));
  1199.       c := at; INC(len,at);
  1200.       WHILE c<len DO
  1201.         HiText.text[c+1] := OldHiText.text[c];
  1202.         INC(c);
  1203.       END;
  1204.       HiText.text[c+1] := col;
  1205.       REPEAT
  1206.         HiText.text[c+2] := OldHiText.text[c];
  1207.         INC(c);
  1208.       UNTIL HiText.text[c-1]=0X;
  1209.     END;
  1210.     IF HiText.next#NIL THEN HiText.next.prev := SYS.ADR(HiText) END;
  1211.     IF HiText.prev#NIL THEN HiText.prev.next := SYS.ADR(HiText) END;
  1212.   END HiLite;
  1213.  
  1214.  
  1215.   PROCEDURE UnHiLite();
  1216.  
  1217.   BEGIN
  1218.     IF HiText.next#NIL THEN HiText.next.prev := OldHiText END;
  1219.     IF HiText.prev#NIL THEN HiText.prev.next := OldHiText END;
  1220.   END UnHiLite;
  1221.  
  1222.  
  1223.   PROCEDURE Search(): BOOLEAN;
  1224.   (* searches string and hilites it if found. result is TRUE if string found *)
  1225.  
  1226.   BEGIN
  1227.     i := 0;
  1228.     IF BottomLine.len<NumColumns THEN m := BottomLine.len ELSE m := NumColumns END;
  1229.     WHILE i<BottomLine.size DO
  1230.       j := 0; k := i;
  1231.       WHILE CAP(BottomLine.text[k])=FindStr[j] DO
  1232.         INC(j); INC(k);
  1233.         IF FindStr[j]=0X THEN
  1234.           SYS.SETREG(0,TryBottomnext());
  1235.           FindLine := BottomLine;
  1236.           HiLite(k-flen,flen);
  1237.           found := w; RETURN w;
  1238.         END;
  1239.       END;
  1240.       INC(i);
  1241.     END;
  1242.     RETURN f;
  1243.   END Search;
  1244.  
  1245.  
  1246.   PROCEDURE ShowInfo(Fast: BOOLEAN);
  1247.   VAR IStr : String;
  1248.       fmt  : StringPtr;
  1249.       data : STRUCT name : e.STRPTR;
  1250.                     perc : LONGINT;
  1251.                     tlen : LONGINT;
  1252.                     flen : LONGINT;
  1253.                     lins : LONGINT;
  1254.              END;
  1255.   BEGIN
  1256.     data.name := SYS.ADR(OldName);
  1257.     data.perc := TextLength * 100 DIV FileLength;
  1258.     data.tlen := TextLength;
  1259.     data.flen := FileLength;
  1260.     data.lins := AnzLines-1;
  1261.     fmt := LocStr(MSGINFOFMT);
  1262.     e.RawDoFmt(fmt^,SYS.ADR(data),StuffChar,SYS.ADR(IStr));
  1263.     IStr[0] := 7X; IF numColors<4 THEN IStr[0] := 2X END;
  1264.     i := SHORT(str.Length(IStr));
  1265.     REPEAT IStr[i] := 20X; INC(i) UNTIL (i>=LEN(IStr)-2) OR (i>=NumColumns+2);
  1266.     IStr[i] := 0X;
  1267.     CopyToWriteText(SYS.ADR(IStr));
  1268.     AddBottomLine(SYS.ADR(writeText),Fast);
  1269.     Info := w;
  1270.     Scroll := f;
  1271.   END ShowInfo;
  1272.  
  1273.  
  1274.   PROCEDURE GetString(VAR str: ARRAY OF CHAR; int: BOOLEAN);
  1275.   VAR
  1276.     msg: I.IntuiMessagePtr;
  1277.     class: LONGSET;
  1278.     oldheight: INTEGER;
  1279.  
  1280.   BEGIN
  1281.     MakeThink(f,f,w);
  1282.     Busy;
  1283.     NuWindow.leftEdge    := 100;
  1284.     NuWindow.topEdge     := NuScreen.height DIV 2 - 6;
  1285.     IF Scrollable THEN INC(NuWindow.topEdge,ri.ryOffset) END;
  1286.     NuWindow.width       := NuScreen.width-200;
  1287.     NuWindow.height      := Screen.font.ySize+4;
  1288.     NuWindow.blockPen    := 1;
  1289.     NuWindow.idcmpFlags  := LONGSET{I.gadgetUp,I.activeWindow,I.inactiveWindow};
  1290.     NuWindow.flags       := LONGSET{I.rmbTrap,I.activate,I.noCareRefresh};
  1291.     NuWindow.firstGadget := SYS.ADR(StrGadget);
  1292.     NuWindow.screen      := Screen;
  1293.     NuWindow.type        := I.customScreen;
  1294.     StrGadget.leftEdge   := 4;
  1295.     StrGadget.topEdge    := 2;
  1296.     StrGadget.width      := NuWindow.width-8;
  1297.     StrGadget.height     := NuWindow.height-4;
  1298.     StrGadget.activation := {I.stringCenter,I.relVerify};
  1299.     IF int THEN INCL(StrGadget.activation,I.longint) END;
  1300.     StrGadget.gadgetType := I.strGadget;
  1301.     StrGadget.specialInfo:= SYS.ADR(StrInfo);
  1302.     StrInfo.buffer       := SYS.ADR(str);
  1303.     StrInfo.maxChars     := SHORT(LEN(str))-1;
  1304.     oldheight := Screen.height;
  1305.     IF Scrollable THEN INC(Screen.height,Screen.height) END;
  1306.     win := I.OpenWindow(NuWindow);
  1307.     Screen.height := oldheight;
  1308.     IF win#NIL THEN
  1309.       e.WaitPort(win.userPort);
  1310.       SYS.SETREG(0,I.ActivateGadget(StrGadget,win,NIL));
  1311.       LOOP
  1312.         e.WaitPort(win.userPort);
  1313.         msg := e.GetMsg(win.userPort);
  1314.         IF msg#NIL THEN
  1315.           class := msg.class;
  1316.           e.ReplyMsg(msg);
  1317.           IF (I.gadgetUp IN class) OR (I.inactiveWindow IN class) THEN
  1318.             EXIT
  1319.           END;
  1320.         END;
  1321.       END;
  1322.       I.CloseWindow(win); win := NIL;
  1323.     END;
  1324.     UnBusy;
  1325.   END GetString;
  1326.  
  1327.  
  1328.   PROCEDURE Help; (* executed when HELP or H is pressed *)
  1329.   VAR
  1330.     i,j: INTEGER;
  1331.     help: ARRAY 26 OF StringPtr;
  1332.  
  1333.   BEGIN
  1334.     help[ 0] := SYS.ADR("");
  1335.     help[ 1] := LocStr(MSGH1);
  1336.     help[ 2] := SYS.ADR("");
  1337.     help[ 3] := LocStr(MSGH2);
  1338.     help[ 4] := LocStr(MSGH3);
  1339.     help[ 5] := LocStr(MSGH4);
  1340.     help[ 6] := LocStr(MSGH5);
  1341.     help[ 7] := LocStr(MSGH6);
  1342.     help[ 8] := LocStr(MSGH7);
  1343.     help[ 9] := LocStr(MSGH8);
  1344.     help[10] := LocStr(MSGH9);
  1345.     help[11] := LocStr(MSGH10);
  1346.     help[12] := LocStr(MSGH11);
  1347.     help[13] := LocStr(MSGH12);
  1348.     help[14] := LocStr(MSGH13);
  1349.     help[15] := LocStr(MSGH14);
  1350.     help[16] := LocStr(MSGH15);
  1351.     help[17] := LocStr(MSGH16);
  1352.     help[18] := LocStr(MSGH17);
  1353.     help[19] := LocStr(MSGH18);
  1354.     help[20] := SYS.ADR("");
  1355.     help[21] := LocStr(MSGH19);
  1356.     help[22] := LocStr(MSGH20);
  1357.     help[23] := LocStr(MSGH21);
  1358.     help[24] := SYS.ADR("");
  1359.     help[25] := LocStr(MSGH22);
  1360.  
  1361.     ClearBitMaps();
  1362.     j := (NumLines - 26) DIV 2; IF j<0 THEN j:=0 END;
  1363.     i := 0;
  1364.     WHILE (i<26) & (i+j<NumLines) DO
  1365.       WriteTo(help[i],j+i);
  1366.       INC(i);
  1367.     END;
  1368.     LOOP
  1369.       e.WaitPort(Window.userPort);
  1370.       MyMsgPtr := e.GetMsg(Window.userPort);
  1371.       IF (LONGSET{I.rawKey,I.mouseButtons}*MyMsgPtr.class#LONGSET{}) & (MyMsgPtr.code<128) THEN EXIT END;
  1372.       e.ReplyMsg(MyMsgPtr);
  1373.     END;
  1374.     e.ReplyMsg(MyMsgPtr);
  1375.     BottomLine := TopLine;
  1376.     NewDisplay
  1377.   END Help;
  1378.  
  1379.  
  1380.   PROCEDURE Bottom;  (* executed when END or B is pressed *)
  1381.  
  1382.   BEGIN
  1383.     WaitAllRead;
  1384.     BottomLine := LastLine;
  1385.     NewDisplay
  1386.   END Bottom;
  1387.  
  1388.  
  1389.   PROCEDURE Space(): BOOLEAN;  (* executed if space or LMB is pressed *)
  1390.   (* IF result=w THEN EXIT END *)
  1391.  
  1392.   BEGIN
  1393.     IF (MyFile=NIL) & (BottomLine.next=NIL) THEN        (* End of file? *)
  1394.       IF End THEN RETURN w ELSE End := w END;
  1395.     ELSE
  1396.       End := f;
  1397.     END;
  1398.     IF Down THEN
  1399.       Scroll := ~Scroll;
  1400.       IF ~Scroll OR End THEN ShowInfo(Fast) END;
  1401.     ELSE
  1402.       Down := w;
  1403.       Scroll := w;
  1404.     END;
  1405.     Fast := Shift;
  1406.     RETURN f;
  1407.   END Space;
  1408.  
  1409.  
  1410.   PROCEDURE BackSpace;  (* executed if backspace or RMB is pressed *)
  1411.  
  1412.   BEGIN
  1413.     Fast := Shift;
  1414.     Scroll := Down OR ~Scroll;
  1415.     Down := f
  1416.   END BackSpace;
  1417.  
  1418.  
  1419. BEGIN
  1420.   (* $IF SmallData *)
  1421.   SYS.SETREG(13,e.exec.thisTask.userData);
  1422.   (* $END *)
  1423.   SYS.SETREG(0,e.Wait(mySig));
  1424.  
  1425.   Down := w; End := f; Find[0] := 0X; Goto[0] := 0X;
  1426.  
  1427.   LOOP
  1428.  
  1429.     IF NewDisp THEN NewDisp := f; NewDisplay END;
  1430.  
  1431. (*------  Type Text:  ------*)
  1432.  
  1433.     LOOP
  1434.       IF Scroll THEN
  1435.         IF Down THEN
  1436.           ScrollDown(Fast);
  1437.           Scroll := (MyFile#NIL) OR (BottomLine.next#NIL);
  1438.         ELSE
  1439.           ScrollUp(Fast);
  1440.           Scroll := (TopLine.prev#NIL) & (TopLine.prev.prev#NIL);
  1441.         END;
  1442.       ELSE
  1443.         MakeThink(f,f,w);
  1444.         e.WaitPort(Window.userPort);
  1445.       END;
  1446.  
  1447.       MyMsgPtr := e.GetMsg(Window.userPort);
  1448.  
  1449.       IF (MyMsgPtr#NIL) THEN
  1450.         IF ~(I.inactiveWindow IN MyMsgPtr.class) THEN EXIT END;
  1451.         e.ReplyMsg(MyMsgPtr);
  1452.         I.OldModifyIDCMP(Window,MyIdcmp-LONGSET{I.mouseButtons});
  1453.         e.WaitPort(Window.userPort);
  1454.         I.OldModifyIDCMP(Window,MyIdcmp);
  1455.       END;
  1456.     END;
  1457.  
  1458.     MyMsg := MyMsgPtr^;
  1459.     e.ReplyMsg(MyMsgPtr);
  1460.  
  1461.  
  1462.     Shift := {ie.lShift,ie.rShift,ie.capsLock} * MyMsg.qualifier # {};
  1463.     Alt   := {ie.lAlt  ,ie.rAlt}               * MyMsg.qualifier # {};
  1464.     Sync  := ~ (ie.control IN MyMsg.qualifier);
  1465.  
  1466.     IF ~Sync THEN Shift := w END;
  1467.  
  1468.  
  1469.     IF (I.rawKey       IN MyMsg.class) & (MyMsg.code<80H) OR
  1470.        (I.mouseButtons IN MyMsg.class) & ({ie.leftButton,ie.rightButton}*MyMsg.qualifier#{})
  1471.     THEN
  1472.       wasInfo := f;
  1473.       IF Info THEN DelLine(Shift); wasInfo := w; END;
  1474.     END;
  1475.  
  1476.  
  1477.     IF I.mouseButtons IN MyMsg.class THEN
  1478.  
  1479.       IF    (ie.leftButton IN MyMsg.qualifier)   & Space()   THEN EXIT
  1480.       ELSIF ie.rightButton IN MyMsg.qualifier THEN BackSpace END;
  1481.  
  1482.     ELSIF (I.rawKey IN MyMsg.class) & (MyMsg.code<80H) THEN
  1483.  
  1484.       CASE MyMsg.code OF
  1485.  
  1486.       | SPACE: IF Space() THEN EXIT END                     (* Space *)
  1487.  
  1488.       | BS:    BackSpace                                    (* BackSpace *)
  1489.  
  1490.       | DOWN,NK2,NK3:                                       (* Down *)
  1491.  
  1492.           IF Shift THEN
  1493.             Scroll := ~Down OR ~Scroll OR ~Fast;
  1494.             Fast := w; Down := w;
  1495.           ELSE
  1496.             IF Alt OR (MyMsg.code=NK3) THEN
  1497.               IF BottomLine.next#NIL THEN BottomLine := BottomLine.next END;
  1498.               NewDisplay;
  1499.             ELSE
  1500.               ScrollDown(w);
  1501.             END;
  1502.             Scroll := f;
  1503.           END;
  1504.  
  1505.       | UP,NK8,NK9:                                        (* Up *)
  1506.  
  1507.           IF Shift THEN
  1508.             Scroll := Down OR ~Scroll OR ~Fast;
  1509.             Fast := w; Down := f;
  1510.           ELSE
  1511.             IF Alt OR (MyMsg.code=NK9) THEN
  1512.               IF TopLine.prev#NIL THEN
  1513.                 i := NumLines-1;
  1514.                 BottomLine := TopLine;
  1515.                 WHILE (i>0) & (BottomLine.prev#NIL) DO
  1516.                   BottomLine := BottomLine.prev;
  1517.                   DEC(i);
  1518.                 END;
  1519.                 NewDisplay;
  1520.               END;
  1521.             ELSE
  1522.               ScrollUp(w);
  1523.             END;
  1524.             Scroll := f;
  1525.           END;
  1526.  
  1527.       | CR,ENTER: ScrollDown(f); Scroll := f;              (* CR *)
  1528.  
  1529.       | NK7: BottomLine := FirstLine; NewDisplay           (* Home *)
  1530.  
  1531.       | NK1: Bottom                                        (* End *)
  1532.  
  1533.       | F1..F10:                                           (* F1..F10 *)
  1534.  
  1535.           i := MyMsg.code-F1;
  1536.           IF ~ Shift & (TextMarkers[i]#NIL) THEN
  1537.             BottomLine := TextMarkers[i];
  1538.             NewDisplay;
  1539.           ELSE
  1540.             TextMarkers[i] := TopLine;
  1541.           END
  1542.  
  1543.       | NK0:  IF ~wasInfo THEN ShowInfo(Shift) END;        (* NK 0 *)
  1544.  
  1545.       | HELP: Help                                         (* Help *)
  1546.  
  1547.       | ESC:  EXIT                                         (* Quit *)
  1548.  
  1549.       | NK5:  IF wasInfo THEN EXIT ELSE ShowInfo(Shift)END; (* safe Quit *)
  1550.  
  1551.       ELSE
  1552.  
  1553.         IF MyMsg.code<40H THEN (* examine vanilla keycode: *)
  1554.  
  1555.           chr := KeyMap[MyMsg.code];
  1556.  
  1557.           CASE chr OF
  1558.  
  1559.           | "t": BottomLine := FirstLine; NewDisplay       (* Home *)
  1560.  
  1561.           | "b": Bottom;                                   (* End *)
  1562.  
  1563.           | "f","n","p":                                   (* Find, Next, Previous *)
  1564.  
  1565.             IF chr="f" THEN
  1566.               GetString(Find,f);
  1567.               BottomLine := TopLine;
  1568.               refresh := w; NewDisplay; refresh := f;
  1569.               FindLine := NIL; flen := 0;
  1570.               LOOP
  1571.                 FindStr[flen] := CAP(Find[flen]);
  1572.                 IF    FindStr[flen]>80X THEN DEC(FindStr[flen],32)
  1573.                 ELSIF FindStr[flen]=0X  THEN EXIT END;
  1574.                 INC(flen);
  1575.               END;
  1576.             END;
  1577.             found := f;
  1578.             IF FindStr[0]#0X THEN
  1579.               Busy;
  1580.               i := NumLines;
  1581.               IF FindLine#NIL THEN FindLine := FindLine.next END;
  1582.               WHILE (i>0) & (BottomLine#NIL) & (BottomLine#FindLine) DO
  1583.                 BottomLine := BottomLine^.prev; DEC(i);
  1584.               END;
  1585.               IF (BottomLine#FindLine) OR (BottomLine=NIL) THEN BottomLine := TopLine END;
  1586.               IF chr#"p" THEN (* next *)
  1587.                 WHILE (BottomLine#NIL) & ~ Search() DO
  1588.                   SYS.SETREG(0,TryBottomnext());
  1589.                   BottomLine := BottomLine.next;
  1590.                 END;
  1591.               ELSE                   (* previous *)
  1592.                 IF BottomLine.prev#NIL THEN BottomLine:=BottomLine.prev END;
  1593.                 REPEAT
  1594.                   BottomLine := BottomLine.prev
  1595.                 UNTIL (BottomLine=NIL) OR Search();
  1596.               END;
  1597.               IF BottomLine#NIL THEN
  1598.                 li := NumLines DIV 2;
  1599.                 WHILE (li>0) & (BottomLine.prev#NIL) DO BottomLine := BottomLine.prev; DEC(li) END;
  1600.               END;
  1601.               UnBusy;
  1602.             END;
  1603.  
  1604.             IF ~ found THEN
  1605.               I.DisplayBeep(NIL);
  1606.               BottomLine := TopLine;
  1607.             END;
  1608.             NewDisplay;
  1609.             IF found THEN UnHiLite END;
  1610.  
  1611.           | "w":                                           (* write block *)
  1612.  
  1613.             IF (TextMarkers[0]#NIL) & (TextMarkers[1]#NIL) & ~ print & ~ save THEN
  1614.               savefrom := 0; savesize := 0;
  1615.               l := TextMarkers[0].prev; WHILE l.prev#NIL DO l := l.prev; INC(savefrom,l.len) END;
  1616.               l := TextMarkers[1].prev; WHILE l#NIL DO INC(savesize,l.len); l := l.prev END;
  1617.               l := TextMarkers[1]; i := NumLines; WHILE (i>1) & (l#NIL) DO DEC(i); INC(savesize,LONG(l.len)); l := l.next END;
  1618.               DEC(savesize,savefrom);
  1619.               IF savesize>0 THEN
  1620.                 GetString(WriteName,f);
  1621.                 WaitAllRead; save := w; e.Signal(SYS.ADR(Me.task),mySig);
  1622.                 BottomLine := TopLine;
  1623.                 NewDisplay;
  1624.               END
  1625.             END
  1626.  
  1627.           | "o":                                           (* Printout *)
  1628.  
  1629.             IF Shift & Alt & ~print & ~save THEN
  1630.               nameptr := SYS.ADR(Name);
  1631.               e.RawDoFmt("TYPE %s TO PRT:",SYS.ADR(nameptr),StuffChar,SYS.ADR(PStr));
  1632.               WaitAllRead; print := w; e.Signal(SYS.ADR(Me.task),mySig);
  1633.             END
  1634.  
  1635.           | "l":                                           (* Load Text *)
  1636.  
  1637.             ClearBitMaps;
  1638.             NewText := w; e.Signal(SYS.ADR(Me.task),mySig);
  1639.             REPEAT UNTIL (mySigBit IN e.Wait(mySig)) & ~ NewText |
  1640.  
  1641.           | "g":                                           (* goto *)
  1642.  
  1643.             GetString(Goto,w);
  1644.             li := SHORT(StrInfo.longInt);
  1645.             Busy;
  1646.             BottomLine := FirstLine;
  1647.             WHILE (li>0) & TryBottomnext() DO
  1648.               BottomLine := BottomLine.next;
  1649.               DEC(li)
  1650.             END;
  1651.             UnBusy;
  1652.             NewDisplay
  1653.  
  1654.           | "h":     Help                                  (* Help *)
  1655.  
  1656.           | "q","x": IF wasInfo THEN EXIT ELSE ShowInfo(Shift) END; (* safe Quit *)
  1657.  
  1658.           ELSE END;
  1659.  
  1660.         END;   (* IF MyMsg.code<40H THEN *)
  1661.  
  1662.       END;   (* CASE MyMsg.code OF *)
  1663.  
  1664.     END;   (* IF I.rawKey IN MyMsg.class THEN *)
  1665.  
  1666.   END;   (* LOOP *)
  1667.  
  1668.   Done := w;
  1669.   e.Signal(SYS.ADR(Me.task),mySig);
  1670.   LOOP SYS.SETREG(0,e.Wait(LONGSET{})) END;
  1671.  
  1672. END ShowProc;
  1673.  
  1674. (* $Debug= *)
  1675.  
  1676. (*--------------------------  File Requester:  ----------------------------*)
  1677.  
  1678.  
  1679. PROCEDURE FileReq(VAR Name: String);
  1680.  
  1681. CONST
  1682.   dummy     = u.user + 80000H;
  1683.   taghail   = dummy + 1;
  1684.   window    = dummy + 2;
  1685.   leftEdge  = dummy + 3;         (* Initialize LeftEdge                  *)
  1686.   topEdge   = dummy + 4;         (* Initialize TopEdge                   *)
  1687.   width     = dummy + 5;
  1688.   height    = dummy + 6;
  1689.   hookFunc  = dummy + 7;         (* Hook function pointer                *)
  1690.   file      = dummy + 8;         (* Initial name of file follows         *)
  1691.   dir       = dummy + 9;         (* Initial string for filerequest dir   *)
  1692.   pattern   = dummy + 10;
  1693.   funcFlags = dummy + 20;
  1694.   fiDir     = u.user + 50;
  1695.   longPath  = 0;
  1696.   patGad    = 0;
  1697.  
  1698. VAR
  1699.   fr: FileRequesterPtr;
  1700.   pscr: I.ScreenPtr;
  1701.   res: BOOLEAN;
  1702.  
  1703.   PROCEDURE AllocAslRequest  {asl,-48} (type{0}: LONGINT;
  1704.                                         tag{8}..: e.APTR): FileRequesterPtr;
  1705.   PROCEDURE FreeAslRequest   {asl,-54} (fr{8}: FileRequesterPtr);
  1706.   PROCEDURE RequestFile      {asl,-42} (fr{8}: FileRequesterPtr): e.APTR;
  1707.  
  1708.   PROCEDURE FileRequest{arp,-294}(VAR filereq{8}: FileRequester): BOOLEAN;
  1709.  
  1710. BEGIN
  1711.   j := SHORT(str.Length(Name));
  1712.   WHILE (j>0) & (Name[j]#":") & (Name[j]#"/") DO DEC(j) END;
  1713.   IF j=0 THEN j := -1 END;
  1714.   i := 0;
  1715.   WHILE i<=j DO Dirname[i] := Name[i]; INC(i) END; Dirname[i] := 0X;
  1716.   j := 0;
  1717.   REPEAT Filename[j] := Name[i]; INC(j); INC(i) UNTIL Name[i-1]=0X;
  1718.  
  1719.   LOOP
  1720.     IF I.int.libNode.version >= 37 THEN
  1721.       pscr := I.LockPubScreen(NIL);
  1722.       IF pscr#NIL THEN
  1723.         I.ScreenToFront(pscr);
  1724.         I.UnlockPubScreen(NIL,pscr);
  1725.         EXIT
  1726.       END;
  1727.     END;
  1728.     SYS.SETREG(0,I.WBenchToFront());
  1729.     EXIT
  1730.   END;
  1731.  
  1732.   IF asl=NIL THEN asl := e.OpenLibrary("asl.library",36) END;
  1733.   IF asl#NIL THEN
  1734.     fr := AllocAslRequest(0,taghail, SYS.ADR(MuchText),
  1735.                             file,    SYS.ADR(Filename),
  1736.                             dir,     SYS.ADR(Dirname),
  1737.                             pattern, SYS.ADR(Pattern),
  1738.                             funcFlags,ASH(1,patGad),
  1739.                             u.done);
  1740.     IF fr=NIL THEN Request(LocStr(MSGOOM)^) END;
  1741.     res := RequestFile(fr)#NIL;
  1742.     IF res THEN
  1743.       Filename := fr.ddef^;
  1744.       Dirname  := fr.ddir^;
  1745.     END;
  1746.     FreeAslRequest(fr);
  1747.     IF ~res THEN HALT(d.ok) END;
  1748.   ELSE
  1749.     IF arp=NIL THEN arp := e.OpenLibrary("arp.library",39) END;
  1750.     IF arp#NIL THEN
  1751.       FR.hail := SYS.ADR(MuchText);
  1752.       FR.ddef := SYS.ADR(Filename);
  1753.       FR.ddir := SYS.ADR(Dirname);
  1754.       FR.flags2 := SHORTSET{longPath};
  1755.       FR.wind := NIL;
  1756.       IF ~FileRequest(FR) THEN HALT(d.ok) END;
  1757.     ELSE
  1758.       Request("Need ARP for filereq")
  1759.     END;
  1760.   END;
  1761.   Name := Dirname;
  1762.   i := SHORT(str.Length(Name));
  1763.   IF (i>0) THEN
  1764.     CASE Name[i-1] OF "/",":": ELSE
  1765.       Name[i] := "/"; INC(i);
  1766.     END;
  1767.   END;
  1768.   j := 0;
  1769.   LOOP
  1770.     Name[i] := Filename[j];
  1771.     IF (Name[i]=0X) OR (i=255) THEN EXIT END;
  1772.     INC(i);
  1773.     INC(j);
  1774.   END;
  1775.   Name[i] := 0X;
  1776.   IF Screen#NIL THEN I.ScreenToFront(Screen) END;
  1777.   IF Window#NIL THEN IF I.ActivateWindow(Window) THEN END END;
  1778. END FileReq;
  1779.  
  1780.  
  1781. (*--------------------------  Decrunch:  ----------------------------*)
  1782.  
  1783.  
  1784. PROCEDURE DirExists(name: ARRAY OF CHAR): BOOLEAN; (* $CopyArrays- *)
  1785. VAR lock: d.FileLockPtr;
  1786.     result: BOOLEAN;
  1787.     oldwp: e.APTR;
  1788. BEGIN
  1789.   result := f;
  1790.   oldwp := Me.windowPtr;
  1791.   Me.windowPtr := -1;
  1792.   lock := d.Lock(name,d.sharedLock);
  1793.   IF lock # NIL THEN
  1794.     result := w;
  1795.     d.UnLock(lock)
  1796.   END;
  1797.   Me.windowPtr := oldwp;
  1798.   RETURN result
  1799. END DirExists;
  1800.  
  1801.  
  1802.  
  1803. PROCEDURE Decrunch;
  1804.  
  1805. CONST
  1806.   tagBase    = u.user + ORD("X")*256 + ORD("P");
  1807.   inName     = tagBase+01H;
  1808.   inFH       = tagBase+02H;
  1809.   outName    = tagBase+10H;
  1810.   password   = tagBase+24H;
  1811.   getError   = tagBase+25H;
  1812.   shortError = tagBase+31H;
  1813.   typePacked = 1;
  1814.   flagsPassword = 0;
  1815.  
  1816. TYPE
  1817.   XpkFib = STRUCT
  1818.     type       : LONGINT;    (* Unpacked, packed, archive? *)
  1819.     uLen       : LONGINT;
  1820.     cLen       : LONGINT;
  1821.     nLen       : LONGINT;
  1822.     uCur       : LONGINT;
  1823.     cCur       : LONGINT;
  1824.     id         : LONGINT;
  1825.     packer     : ARRAY 6 OF CHAR;
  1826.     subVersion : INTEGER;
  1827.     masVersion : INTEGER;
  1828.     flags      : LONGSET;
  1829.     head       : ARRAY 16 OF CHAR;
  1830.     ratio      : LONGINT;
  1831.     reserved   : ARRAY 8 OF LONGINT;
  1832.   END;
  1833.  
  1834. VAR
  1835.   file: d.FileHandlePtr;
  1836.   err: LONGINT;
  1837.   xpkFib: XpkFib;
  1838.   errBuf: ARRAY 81 OF CHAR;
  1839.  
  1840.   PROCEDURE ExamineTags {xpk,-36}(VAR fib{8}  : XpkFib;
  1841.                                   tag1{9}..   : e.APTR): LONGINT;
  1842.   PROCEDURE UnpackTags  {xpk,-48}(tag1{8}..   : e.APTR): LONGINT;
  1843.  
  1844. BEGIN
  1845.   Decrunched := f;
  1846.   OldName := Name;
  1847.  
  1848.   IF DirExists("T:") THEN Name := "T:" ELSE Name := "RAM:" END;
  1849.  
  1850.   e.RawDoFmt("mm_%lx.decr",SYS.ADR(Me),StuffChar,SYS.ADR(Name[str.Length(Name)]));
  1851.  
  1852.   IF xpk=NIL THEN
  1853.     xpk := e.OpenLibrary("xpkmaster.library",1);
  1854.   END;
  1855.   IF xpk#NIL THEN
  1856.     err := ExamineTags(xpkFib,inFH,SYS.VAL(LONGINT,MyFile),u.done);
  1857.     IF (err#0) & (err#-20) THEN
  1858.       Request(LocStr(MSGOOM)^)
  1859.     END;
  1860.     IF (err=-20) OR (xpkFib.type#typePacked) THEN
  1861.       Name := OldName;
  1862.       RETURN
  1863.     END;
  1864.     Busy;
  1865.     err := UnpackTags(inFH,   SYS.VAL(LONGINT,MyFile),
  1866.                   outName,    SYS.ADR(Name),
  1867.                   password,   SYS.ADR(Password),
  1868.                   getError,   SYS.ADR(errBuf),
  1869.                   shortError, e.true,
  1870.                   u.done);
  1871.     UnBusy;
  1872.     IF err#0 THEN Request(errBuf) END;
  1873.     file := d.Open(Name,d.oldFile);
  1874.     IF file#NIL THEN
  1875.       Decrunched := w;
  1876.       d.OldClose(MyFile);
  1877.       MyFile := file;
  1878.       RETURN
  1879.     ELSE
  1880.       Request(LocStr(MSGCOF)^);
  1881.     END;
  1882.   END;
  1883.   Name := OldName;
  1884. END Decrunch;
  1885.  
  1886.  
  1887. (*-----------------  Screen Mode Requester:  ------------------------*)
  1888.  
  1889.  
  1890. PROCEDURE GetNode (VAR list: e.List; index: LONGINT): e.NodePtr;
  1891.   VAR n: e.NodePtr;
  1892. BEGIN
  1893.   n := list.head;
  1894.   WHILE index > 0 DO
  1895.     IF n.succ=NIL THEN RETURN NIL END;
  1896.     n := n.succ;
  1897.     DEC(index);
  1898.   END;
  1899.   RETURN n;
  1900. END GetNode;
  1901.  
  1902.  
  1903. PROCEDURE ScreenModeReq (VAR displayID : LONGINT): INTEGER;
  1904. CONST
  1905.   gadLISTVIEW    = 1;
  1906.   gadBUTTONSave  = 2;
  1907.   gadBUTTONUse   = 3;
  1908.   gadBUTTONCancel= 4;
  1909.  
  1910.   Topaz80 = g.TextAttr(SYS.ADR("topaz.font"), 8, SHORTSET{}, SHORTSET{});
  1911.  
  1912. TYPE
  1913.   MyNodePtr = UNTRACED POINTER TO MyNode;
  1914.   MyNode = STRUCT (node: e.Node)
  1915.              displayID: LONGINT;
  1916.            END;
  1917.  
  1918. VAR
  1919.   ng            : gt.NewGadget;
  1920.   gad,glist     : I.GadgetPtr;
  1921.   win           : I.WindowPtr;
  1922.   pub           : I.ScreenPtr;
  1923.   font          : g.TextAttrPtr;
  1924.   width,height  : INTEGER;
  1925.   txW,txH       : INTEGER;
  1926.   result,index  : INTEGER;
  1927.   firstindex    : INTEGER;
  1928.   topborder     : INTEGER;
  1929.   x1,x2,min     : INTEGER;
  1930.   terminated    : BOOLEAN;
  1931.   lvlist        : e.List;
  1932.   lvSelectedTag : LONGINT;
  1933.   vi            : e.APTR;
  1934.   imsg          : I.IntuiMessagePtr;
  1935.   node          : MyNodePtr;
  1936.   dispID        : LONGINT;
  1937.   displayInfo   : g.DisplayInfo;
  1938.   nameInfo      : g.NameInfo;
  1939.  
  1940.  
  1941.   PROCEDURE StrLen (str: e.STRPTR; min: INTEGER): INTEGER;
  1942.   VAR it: I.IntuiText;
  1943.       len: INTEGER;
  1944.   BEGIN
  1945.     (* $IFNOT ClearVars *)
  1946.     len := 0;
  1947.     it.leftEdge := 0; it.topEdge  := 0; it.frontPen := 0; it.backPen  := 0;
  1948.     it.drawMode := SHORTSET{}; it.nextText := NIL;
  1949.     (* $END *)
  1950.     IF str#NIL THEN
  1951.       it.iTextFont := font; it.iText := str;
  1952.       len := I.IntuiTextLength(it);
  1953.     END;
  1954.     IF len > min THEN RETURN len ELSE RETURN min END;
  1955.   END StrLen;
  1956.  
  1957. BEGIN
  1958.   (* $IFNOT ClearVars *)
  1959.   win := NIL; vi := NIL; glist := NIL; pub := NIL; result := 0;
  1960.   (* $END *)
  1961.  
  1962.   LOOP
  1963.     pub := I.LockPubScreen(NIL);         IF pub=NIL THEN EXIT END;
  1964.     vi  := gt.GetVisualInfo(pub,u.done); IF vi =NIL THEN EXIT END;
  1965.     topborder := pub.wBorTop + pub.font.ySize + 1;
  1966.  
  1967.     font := pub.font;
  1968.     txW := pub.rastPort.txWidth; txH := pub.rastPort.txHeight;
  1969.     width := txW * 36 + 16; height := txH * 8 + 32;
  1970.     IF ((width+pub.wBorLeft+pub.wBorRight) > pub.width) OR ((height+topborder+pub.wBorBottom) > pub.height) THEN
  1971.       font := SYS.ADR(Topaz80);
  1972.       txW := 8; txH := 8;
  1973.       width := txW * 36 + 16; height := txH * 8 + 32;
  1974.     END;
  1975.     min := txW * 6;
  1976.  
  1977.     gad := gt.CreateContext(glist);
  1978.  
  1979.     ng.textAttr := font;
  1980.     ng.visualInfo := vi;
  1981.     ng.userData := NIL;
  1982.  
  1983.     ng.leftEdge := 16;
  1984.     ng.height := txH+4;
  1985.     ng.topEdge := topborder+height-ng.height-5;
  1986.     ng.gadgetText := LocStr(MSGSAVE);
  1987.     ng.width := StrLen(ng.gadgetText,min)+8;
  1988.     ng.gadgetID := gadBUTTONSave;
  1989.     ng.flags := LONGSET{};
  1990.     x1 := ng.leftEdge+ng.width;
  1991.  
  1992.     gad := gt.CreateGadget(gt.buttonKind, gad, ng, u.done);
  1993.  
  1994.     ng.gadgetText := LocStr(MSGCANCEL);
  1995.     ng.width := StrLen(ng.gadgetText,min)+8;
  1996.     ng.leftEdge := width-ng.width-8;
  1997.     ng.gadgetID := gadBUTTONCancel;
  1998.     x2 := ng.leftEdge;
  1999.  
  2000.     gad := gt.CreateGadget(gt.buttonKind, gad, ng, u.done);
  2001.  
  2002.     ng.gadgetText := LocStr(MSGUSE);
  2003.     ng.width := StrLen(ng.gadgetText,min)+8;
  2004.     ng.leftEdge := (x1+x2-ng.width) DIV 2;
  2005.     ng.gadgetID := gadBUTTONUse;
  2006.  
  2007.     gad := gt.CreateGadget(gt.buttonKind, gad, ng, u.done);
  2008.  
  2009.     lvlist.head := SYS.ADR(lvlist.tail);
  2010.     lvlist.tail := NIL;
  2011.     lvlist.tailPred := SYS.ADR(lvlist.head);
  2012.  
  2013.     index := 0;
  2014.     firstindex := -1;
  2015.     dispID := g.NextDisplayInfo(g.invalidID);
  2016.  
  2017.     WHILE dispID # g.invalidID DO
  2018.       IF (g.GetDisplayInfoData(NIL,displayInfo,SIZE(displayInfo),g.dtagDisp,dispID) > 0) &
  2019.          (displayInfo.notAvailable = 0) &
  2020.          (LONGSET{g.isHAM,g.isExtraHalfBrite,g.isDualPF} * displayInfo.propertyFlags = LONGSET{}) &
  2021.          (g.GetDisplayInfoData(NIL,nameInfo,SIZE(nameInfo),g.dtagName,dispID) > 0)
  2022.       THEN
  2023.         SYS.ALLOCATE(node);
  2024.         IF node # NIL THEN
  2025.           SYS.ALLOCATE(node.node.name);
  2026.           IF node.node.name # NIL THEN
  2027.             COPY(nameInfo.name,node.node.name^);
  2028.             node.displayID := dispID;
  2029.             e.AddTail(lvlist, node);
  2030.             IF dispID=displayID THEN firstindex := index END;
  2031.             INC(index);
  2032.           ELSE
  2033.             EXIT
  2034.           END;
  2035.         ELSE
  2036.           EXIT
  2037.         END;
  2038.       END;
  2039.       dispID := g.NextDisplayInfo(dispID);
  2040.     END;
  2041.  
  2042.     ng.leftEdge := 16;
  2043.     ng.topEdge := txH+8+topborder;
  2044.     ng.width := width-25;
  2045.     ng.height := txH*6+15;
  2046.     ng.gadgetText := LocStr(MSGCHOOSESM);
  2047.     ng.gadgetID := gadLISTVIEW;
  2048.     ng.flags := LONGSET{gt.highLabel,gt.placeTextAbove};
  2049.  
  2050.     IF firstindex >= 0 THEN lvSelectedTag := gt.lvSelected
  2051.                        ELSE lvSelectedTag := u.ignore END;
  2052.  
  2053.     gad := gt.CreateGadget(gt.listViewKind, gad, ng,
  2054.                     gt.lvLabels,       SYS.ADR(lvlist),
  2055.                     gt.lvShowSelected, NIL,
  2056.                     gt.lvScrollWidth,  txW*2,
  2057.                     I.layoutaSpacing,  2,
  2058.                     lvSelectedTag,     firstindex,
  2059.                     u.done);
  2060.     IF gad = NIL THEN EXIT END;
  2061.  
  2062.     win := I.OpenWindowTagsA(NIL,
  2063.                              I.waLeft,        30,
  2064.                              I.waTop,         20,
  2065.                              I.waInnerWidth,  width,
  2066.                              I.waInnerHeight, height,
  2067.                              I.waTitle,       SYS.ADR(MuchText),
  2068.                              I.waFlags,       LONGSET{I.activate,I.windowDrag,I.windowDepth,I.simpleRefresh,I.rmbTrap},
  2069.                              I.waIDCMP,       gt.listViewIDCMP+gt.buttonIDCMP+LONGSET{I.gadgetUp,I.refreshWindow},
  2070.                              I.waCustomScreen,pub,
  2071.                              I.waGadgets,     glist,
  2072.                              u.done);
  2073.     IF win = NIL THEN EXIT END;
  2074.     gt.RefreshWindow(win, NIL);
  2075.  
  2076.     dispID := displayID;
  2077.     terminated := f;
  2078.  
  2079.     WHILE ~terminated DO
  2080.       e.WaitPort(win.userPort);
  2081.       LOOP
  2082.         IF terminated THEN EXIT END;
  2083.         imsg := gt.GetIMsg(win.userPort);
  2084.         IF imsg=NIL THEN EXIT END;
  2085.         gad := imsg.iAddress;
  2086.   
  2087.         IF I.gadgetUp IN imsg.class THEN
  2088.           CASE gad.gadgetID OF
  2089.           | gadBUTTONSave:   result := 1; displayID := dispID; terminated := w;
  2090.           | gadBUTTONUse:    result := 2; displayID := dispID; terminated := w;
  2091.           | gadBUTTONCancel: terminated := w;
  2092.           | gadLISTVIEW:     node := GetNode(lvlist,imsg.code);
  2093.                              IF node # NIL THEN dispID := node.displayID END;
  2094.           ELSE
  2095.           END;
  2096.         END;
  2097.  
  2098.         IF I.refreshWindow IN imsg.class THEN
  2099.           gt.BeginRefresh(win);
  2100.           gt.EndRefresh(win, I.LTRUE);
  2101.         END;
  2102.  
  2103.         gt.ReplyIMsg(imsg);
  2104.   
  2105.       END;
  2106.     END;
  2107.  
  2108.     EXIT
  2109.   END;
  2110.  
  2111.   IF win   # NIL THEN I.CloseWindow(win) END;
  2112.   IF glist # NIL THEN gt.FreeGadgets(glist) END;
  2113.   IF vi    # NIL THEN gt.FreeVisualInfo(vi) END;
  2114.   IF pub   # NIL THEN I.UnlockPubScreen(NIL,pub) END;
  2115.  
  2116.   RETURN result;
  2117. END ScreenModeReq;
  2118.  
  2119.  
  2120. (*-------------------------------------------------------------------------*)
  2121.  
  2122.  
  2123. PROCEDURE SavePrefs;
  2124.  
  2125. VAR
  2126.   lock: d.FileLockPtr;
  2127.  
  2128.   PROCEDURE SavePrefsName(name: StringPtr);
  2129.   VAR file: d.FileHandlePtr;
  2130.       l: LONGINT;
  2131.   BEGIN
  2132.     file := d.Open(name^,d.newFile);
  2133.     IF file # NIL THEN
  2134.       SYS.SETREG(0,d.Write(file,"FORM",4));
  2135.       l := 16;
  2136.       SYS.SETREG(0,d.Write(file,l,4));
  2137.       SYS.SETREG(0,d.Write(file,"MUMO",4));
  2138.       SYS.SETREG(0,d.Write(file,"DPID",4));
  2139.       l := 4;
  2140.       SYS.SETREG(0,d.Write(file,l,4));
  2141.       SYS.SETREG(0,d.Write(file,id,4));
  2142.       d.OldClose(file);
  2143.     END;
  2144.   END SavePrefsName;
  2145.  
  2146. BEGIN
  2147.   IF DirExists("ENV:") THEN
  2148.     IF ~DirExists("ENV:MuchMore") THEN
  2149.       lock := d.CreateDir("ENV:MuchMore");
  2150.       IF lock#NIL THEN d.UnLock(lock) END;
  2151.     END;
  2152.     SavePrefsName(SYS.ADR("ENV:MuchMore/MuchMore.prefs"))
  2153.   END;
  2154.   IF DirExists("ENVARC:") THEN
  2155.     IF ~DirExists("ENVARC:MuchMore") THEN
  2156.       lock := d.CreateDir("ENVARC:MuchMore");
  2157.       IF lock#NIL THEN d.UnLock(lock) END;
  2158.     END;
  2159.     SavePrefsName(SYS.ADR("ENVARC:MuchMore/MuchMore.prefs"))
  2160.   END;
  2161. END SavePrefs;
  2162.  
  2163.  
  2164. (*-------------------------------------------------------------------------*)
  2165.  
  2166.  
  2167. PROCEDURE LoadPrefs;
  2168.  
  2169. VAR file: d.FileHandlePtr;
  2170.     l,i,s: LONGINT;
  2171.     ok: BOOLEAN;
  2172.  
  2173. BEGIN
  2174.   file := NIL;
  2175.   IF DirExists("PROGDIR:") THEN
  2176.     file := d.Open("PROGDIR:MuchMore.prefs",d.oldFile);
  2177.   END;
  2178.   IF (file=NIL) & DirExists("ENV:") THEN
  2179.     file := d.Open("ENV:MuchMore/MuchMore.prefs",d.oldFile);
  2180.   END;
  2181.   IF file # NIL THEN
  2182.     LOOP
  2183.       IF (d.Read(file,i,4) <= 0)        OR
  2184.          (i # SYS.VAL(LONGINT,"FORM"))  OR
  2185.          (d.Read(file,s,4) <= 0)        OR
  2186.          (d.Read(file,i,4) <= 0)        OR
  2187.          (i # SYS.VAL(LONGINT,"MUMO"))    THEN EXIT END;
  2188.       WHILE w DO
  2189.         IF (d.Read(file,i,4) <= 0)      OR
  2190.            (d.Read(file,s,4) <= 0)        THEN EXIT END;
  2191.         IF ODD(s) THEN INC(s) END;
  2192.         IF (s=4) & (i=SYS.VAL(LONGINT,"DPID")) THEN
  2193.           SYS.SETREG(0,d.Read(file,id,4));
  2194.         ELSE
  2195.           IF s < 0 THEN EXIT END;
  2196.           SYS.SETREG(0,d.Seek(file,s,d.current));
  2197.         END;
  2198.       END;
  2199.  
  2200.       EXIT;
  2201.     END;
  2202.     d.OldClose(file);
  2203.   END;
  2204. END LoadPrefs;
  2205.  
  2206.  
  2207. (*------------------------  Get Tooltypes:  --------------------------*)
  2208.  
  2209.  
  2210. PROCEDURE EvalIcon(icon: DiskObjectPtr);
  2211. VAR tt: StringPtr;
  2212.  
  2213. BEGIN
  2214.   IF icon # NIL THEN
  2215.     tt := FindToolType(icon.toolTypes,"COLORS");     IF (tt # NIL) THEN COPY(tt^,Pens) END;
  2216.     tt := FindToolType(icon.toolTypes,"EXTRASPACE"); IF (tt # NIL) THEN spacing := SHORT(StrToInt(tt,10)) END;
  2217.     tt := FindToolType(icon.toolTypes,"FONT");       IF (tt # NIL) THEN COPY(tt^,FontName) END;
  2218.     tt := FindToolType(icon.toolTypes,"PASSWORD");   IF (tt # NIL) THEN COPY(tt^,Password) END;
  2219.     tt := FindToolType(icon.toolTypes,"NOOSCAN");    IF (tt # NIL) & (MatchToolValue(tt^,"TRUE")) THEN noOscan := w END;
  2220.     tt := FindToolType(icon.toolTypes,"PLANES");     IF (tt # NIL) THEN NuScreen.depth := SHORT(StrToInt(tt,10)) END;
  2221.     tt := FindToolType(icon.toolTypes,"SCROLLMODE"); IF (tt # NIL) THEN scrollmode := SHORT(StrToInt(tt,10)) END;
  2222.     tt := FindToolType(icon.toolTypes,"TABWIDTH");   IF (tt # NIL) THEN tabw := SHORT(StrToInt(tt,10)) END;
  2223.     tt := FindToolType(icon.toolTypes,"TOGGLELACE"); IF (tt # NIL) & (MatchToolValue(tt^,"TRUE")) THEN lace := ~lace END;
  2224.     tt := FindToolType(icon.toolTypes,"TOOLPRI");    IF (tt # NIL) THEN taskpri := SHORT(SHORT(StrToInt(tt,10))) END;
  2225.     FreeDiskObject(icon);
  2226.   END;
  2227. END EvalIcon;
  2228.  
  2229.  
  2230. (*------------------------------  MAIN:  ----------------------------------*)
  2231.  
  2232. BEGIN
  2233.  
  2234. (*------  Init:  ------*)
  2235.  
  2236.   mySigBit := -1;
  2237.   Me := SYS.VAL(d.ProcessPtr,ol.Me);
  2238.   OldDir := Me.currentDir;
  2239.   oldpri := Me.task.node.pri; taskpri := oldpri;
  2240.   WriteName := "PRT:";
  2241.   MemIndex := ChunkSize;
  2242.   Sync := w;
  2243.   FontSize := 8;
  2244.   Pattern := "~(#?.info)";
  2245.   id := g.invalidID;
  2246.   tabw := 8;
  2247.   NuScreen.depth := 2;
  2248.   IF g.gfx.libNode.version >= 37 THEN scrollmode := 1 END;
  2249.  
  2250.   I.GetPrefs(Prefs,SIZE(Prefs)); lace := Prefs.laceWB # SHORTSET{};
  2251.  
  2252.   mySigBit := e.AllocSignal(-1);
  2253.   IF mySigBit<0 THEN HALT(d.fail) END;
  2254.   mySig := LONGSET{mySigBit};
  2255.  
  2256.   iconBase := e.OpenLibrary("icon.library",33);
  2257.  
  2258.   IF loc.base # NIL THEN
  2259.     catalog := loc.OpenCatalog(NIL,"muchmore.catalog",u.end);
  2260.   END;
  2261.  
  2262.   ol.OutOfMemHandler := OutOfMemHandler;
  2263.  
  2264.  
  2265. (*------  Setup:  ------*)
  2266.  
  2267.   NEW(FirstLine);
  2268. (*FirstLine.size := 0;
  2269.   FirstLine.text[0] := 0X; *)
  2270.  
  2271. (*------  Start:  ------*)
  2272.  
  2273.   LoadPrefs;
  2274.  
  2275.   IF ol.wbStarted THEN
  2276.  
  2277.     wbm := ol.wbenchMsg;
  2278.     IF iconBase # NIL THEN
  2279.       oldLace:=lace;
  2280.       j := SHORT(wbm.numArgs); IF j>2 THEN j := 2 END;
  2281.       FOR i := 0 TO j-1 DO
  2282.         lace := oldLace;
  2283.         SYS.SETREG(0,d.CurrentDir(wbm.argList[i].lock));
  2284.         nameptr := wbm.argList[i].name;
  2285.         icon := GetDiskObject(nameptr^);
  2286.         IF (icon=NIL) & (d.base.lib.version >= 37) THEN
  2287.           SYS.SETREG(0,d.CurrentDir(d.GetProgramDir()));
  2288.           icon := GetDiskObject(nameptr^);
  2289.         END;
  2290.         EvalIcon(icon);
  2291.       END;
  2292.     END; (* IF iconBase#NIL *)
  2293.  
  2294.     IF wbm.numArgs >= 2 THEN
  2295.       ArgPtr := wbm.argList^[1].name; Name := ArgPtr^;
  2296.       SYS.SETREG(0,d.CurrentDir(wbm.argList^[1].lock));
  2297.     ELSE
  2298.       SYS.SETREG(0,d.CurrentDir(wbm.argList^[0].lock));
  2299.       FileReq(Name)
  2300.     END;
  2301.  
  2302.   ELSE
  2303.  
  2304.     IF d.dos.lib.version < 37 THEN
  2305.       IF ol.dosCmdLen > 1 THEN
  2306.         CommLine := ol.dosCmdBuf;
  2307.         j := 0;
  2308.         LOOP
  2309.           i := 0;
  2310.           WHILE CommLine[j]=20X DO INC(j) END;
  2311.           IF CommLine[j]=0AX THEN EXIT END;
  2312.           IF CommLine[j]='"' THEN
  2313.             INC(j);
  2314.             LOOP
  2315.               CASE CommLine[j] OF
  2316.               | '"': INC(j); EXIT
  2317.               | 0AX:                     EXIT
  2318.               ELSE
  2319.                 option[i] := CommLine[j]; INC(i); INC(j);
  2320.               END;
  2321.             END;
  2322.           ELSE
  2323.             WHILE (CommLine[j]#0AX) & (CommLine[j]#20X) DO
  2324.               option[i] := CommLine[j]; INC(i); INC(j);
  2325.             END;
  2326.           END;
  2327.           option[i]:= 0X;
  2328.           IF option="?"  THEN Request(usage) END;
  2329.           IF option[0]="-" THEN
  2330.             CASE CAP(option[1]) OF
  2331.               "A": tabw := SHORT(StrToInt(SYS.ADR(option[2]),10)) |
  2332.               "B": NuScreen.depth := SHORT(StrToInt(SYS.ADR(option[2]),10)) |
  2333.               "C": GetStr(SYS.ADR(option[2]),Pens) |
  2334.               "E": spacing := SHORT(StrToInt(SYS.ADR(option[2]),10)) |
  2335.               "F": GetStr(SYS.ADR(option[2]),FontName) |
  2336.               "L": lace := ~lace |
  2337.               "P": GetStr(SYS.ADR(option[2]),Password) |
  2338.               "S": scrollmode := SHORT(StrToInt(SYS.ADR(option[2]),10)) |
  2339.               "T": taskpri := SHORT(SHORT(StrToInt(SYS.ADR(option[2]),10))) |
  2340.             ELSE
  2341.               Request(usage);
  2342.             END;
  2343.           ELSE
  2344.             COPY(option,Name);
  2345.           END;
  2346.         END;
  2347.       END;
  2348.  
  2349.     ELSE  (* d.dos.lib.version >= 37 *)
  2350.  
  2351.       IF iconBase#NIL THEN
  2352.         oldcd := d.CurrentDir(d.GetProgramDir());
  2353.         IF d.GetProgramName(Name,LEN(Name)) THEN
  2354.           icon := GetDiskObject(Name);
  2355.           EvalIcon(icon);
  2356.           Name[0] := 0X;
  2357.         END;
  2358.         oldcd := d.CurrentDir(oldcd);
  2359.       END;
  2360.  
  2361.       rd := d.ReadArgs("A=TABWIDTH/N/K,B=PLANES/N/K,C=COLORS/K,D=DISPMODEREQ/S,E=EXTRASPACE/N/K,F=FONT/K,N=NOOSCAN/S,P=PASSWORD/K,S=SCROLLMODE/N/K,T=TOOLPRI/N/K,FILE",args,NIL);
  2362.       IF rd=NIL THEN
  2363.         SYS.SETREG(0,d.PrintFault(d.IoErr(),NIL));
  2364.         HALT(d.warn)
  2365.       END;
  2366.       IF args.a # NIL THEN tabw := SHORT(args.a^) END;
  2367.       IF args.b # NIL THEN NuScreen.depth := SHORT(args.b^) END;
  2368.       IF args.c # NIL THEN COPY(args.c^,Pens) END;
  2369.       IF args.d # NIL THEN modeReq := w END;
  2370.       IF args.e # NIL THEN spacing := SHORT(args.e^) END;
  2371.       IF args.f # NIL THEN COPY(args.f^,FontName) END;
  2372.       IF args.n # NIL THEN noOscan := w END;
  2373.       IF args.p # NIL THEN COPY(args.p^,Password) END;
  2374.       IF args.s # NIL THEN scrollmode := SHORT(args.s^) END;
  2375.       IF args.t # NIL THEN taskpri := SHORT(SHORT(args.t^)) END;
  2376.       IF args.file # NIL THEN COPY(args.file^,Name) END;
  2377.       d.FreeArgs(rd); rd := NIL;
  2378.     END;
  2379.   END;
  2380.  
  2381.   IF tabw < 1 THEN tabw := 1 END;
  2382.  
  2383.   IF NuScreen.depth < 1 THEN NuScreen.depth := 1 END;
  2384.   IF NuScreen.depth > 2 THEN NuScreen.depth := 2 END;
  2385.  
  2386.   IF taskpri#oldpri THEN SYS.SETREG(0,e.SetTaskPri(Me,taskpri)) END;
  2387.  
  2388.   IF FontName[0]#0X THEN
  2389.     i := 0;
  2390.     j := SHORT(str.Length(FontName));
  2391.     LOOP
  2392.       IF i >= j THEN EXIT END;
  2393.       IF FontName[i]='/' THEN
  2394.         FontName[i] := 0X;
  2395.         FontSize := SHORT(StrToInt(SYS.ADR(FontName[i+1]),10));
  2396.         j := i;
  2397.         EXIT
  2398.       END;
  2399.       INC(i);
  2400.     END;
  2401.     IF j<LEN(FontName)-6 THEN
  2402.       e.CopyMem(".font",FontName[j],6);
  2403.     END;
  2404.   END;
  2405.  
  2406.   IF FontSize>50 THEN FontSize := 50 END;
  2407.   IF FontSize< 5 THEN FontSize :=  5 END;
  2408.  
  2409.   IF spacing< 0 THEN spacing :=  0 END;
  2410.   IF spacing>20 THEN spacing := 20 END;
  2411.  
  2412.   IF modeReq & (gt.base#NIL) THEN
  2413.     IF ScreenModeReq(id) = 1 THEN SavePrefs END;
  2414.   END;
  2415.  
  2416. (*------  Open File:  ------*)
  2417.  
  2418.   LOOP
  2419.     MyFile := d.Open(Name,d.oldFile);
  2420.     IF MyFile#NIL THEN EXIT END;
  2421.     FileReq(Name)
  2422.   END;
  2423.  
  2424. (*------------------------  Open Display:  --------------------------------*)
  2425.  
  2426. (*------  Open Screen:  ------*)
  2427.  
  2428.   IF lace THEN
  2429.     NuScreen.viewModes := {g.hires,g.lace};
  2430.     NuScreen.height := g.gfx.normalDisplayRows*2
  2431.   ELSE
  2432.     NuScreen.viewModes := {g.hires};
  2433.     NuScreen.height := g.gfx.normalDisplayRows
  2434.   END;
  2435.   NuScreen.width  := g.gfx.normalDisplayColumns;
  2436.   NuScreen.type   := I.customScreen+{I.screenQuiet};
  2437.  
  2438.   LOOP
  2439.  
  2440.     IF I.int.libNode.version >= 37 THEN
  2441.  
  2442.       IF id=g.invalidID THEN
  2443.         id := g.defaultMonitorID;
  2444.         pub := I.LockPubScreen("Workbench");
  2445.         IF pub # NIL THEN
  2446.           id := g.GetVPModeID(SYS.ADR(pub.viewPort));
  2447.           I.UnlockPubScreen(NIL,pub);
  2448.         END;
  2449.       END;
  2450.  
  2451.       IF g.GetDisplayInfoData(NIL,dims,SIZE(dims),g.dtagDims,id) > 0 THEN
  2452.         IF noOscan THEN
  2453.           NuScreen.width     := dims.nominal.maxX - dims.nominal.minX + 1;
  2454.           NuScreen.height    := dims.nominal.maxY - dims.nominal.minY + 1;
  2455.           overscanTag := u.ignore;
  2456.         ELSE
  2457.           NuScreen.width     := dims.txtOScan.maxX - dims.txtOScan.minX + 1;
  2458.           NuScreen.height    := dims.txtOScan.maxY - dims.txtOScan.minY + 1;
  2459.           overscanTag := I.saOverscan;
  2460.         END;
  2461.         IF g.GetDisplayInfoData(NIL,disp,SIZE(disp),g.dtagDisp,id) > 0 THEN
  2462.           lace := g.isLace IN disp.propertyFlags;
  2463.           Scrollable := (g.isDraggable IN disp.propertyFlags) (* & ((g.gfx.libNode.version<39) OR ~(20 IN disp.propertyFlags)) *);
  2464.           IF scrollmode=3 THEN Scrollable := f END;
  2465.           IF Scrollable THEN INC(NuScreen.height,NuScreen.height) END;
  2466.  
  2467.           Screen := I.OpenScreenTags(NuScreen,
  2468.                                      I.saDisplayID,id,
  2469.                                      overscanTag,I.oScanText,
  2470.                                      I.saPens,SYS.ADR("\xFF\xFF"),
  2471.                                      u.end);
  2472.         END;
  2473.       END;
  2474.  
  2475.     ELSE
  2476.  
  2477.       Scrollable := w;
  2478.       IF scrollmode=3 THEN Scrollable := f END;
  2479.       IF Scrollable THEN INC(NuScreen.height,NuScreen.height) END;
  2480.       Screen := I.OpenScreen(NuScreen);
  2481.  
  2482.     END;
  2483.  
  2484.     IF Screen#NIL THEN EXIT END;
  2485.  
  2486.     DEC(NuScreen.depth);
  2487.     IF NuScreen.depth=0 THEN Request(LocStr(MSGCOS)^) END;
  2488.   END;
  2489.  
  2490.   numColors := ASH(LONG(1),NuScreen.depth);
  2491.  
  2492.   rp := SYS.ADR(Screen.rastPort);
  2493.   BM := rp.bitMap;
  2494.   ri := Screen.viewPort.rasInfo;
  2495.  
  2496.  
  2497.   IF Pens[0]#0X THEN
  2498.     i := 0;
  2499.     chptr := SYS.ADR(Pens);
  2500.     Pens[LEN(Pens)-1] := 0X;
  2501.     LOOP
  2502.       Cols[i] := SHORT(StrToInt(SYS.VAL(StringPtr,chptr),16));
  2503.       INC(i); IF i=4 THEN EXIT END;
  2504.       WHILE (chptr^#0X) & (chptr^#",") DO
  2505.         chptr:=SYS.VAL(e.APTR,SYS.VAL(LONGINT,chptr)+1)
  2506.       END;
  2507.       IF chptr^="," THEN
  2508.         chptr:=SYS.VAL(e.APTR,SYS.VAL(LONGINT,chptr)+1)
  2509.       ELSE
  2510.         EXIT
  2511.       END;
  2512.     END;
  2513.     g.LoadRGB4(SYS.ADR(Screen.viewPort),Cols,i);
  2514.   END;
  2515.  
  2516.  
  2517. (*------  Open Font:  ------*)
  2518.  
  2519.   IF FontName[0]#0X THEN
  2520.     MyAttr.name := SYS.ADR(FontName);
  2521.     MyAttr.ySize := FontSize;
  2522.     IF diskFontBase=NIL THEN diskFontBase := e.OpenLibrary("diskfont.library",33) END;
  2523.     IF diskFontBase#NIL THEN MyFont := OpenDiskFont(MyAttr) END;
  2524.     IF (MyFont#NIL) & ~(g.proportional IN MyFont.flags) THEN g.SetFont(rp,MyFont) END;
  2525.   END;
  2526.  
  2527.   LOOP
  2528.     fontWidth  := rp.font.xSize;
  2529.     fontHeight := rp.font.ySize;
  2530.     IF (fontWidth<=50) OR (fontHeight<=50) & (fontWidth>2) & (fontHeight>2) THEN EXIT END;
  2531.     MyAttr.name := SYS.ADR("topaz.font");
  2532.     MyAttr.ySize := 8;
  2533.     MyFont := g.OpenFont(MyAttr);
  2534.     IF MyFont=NIL THEN HALT(d.fail) END;
  2535.     g.SetFont(rp,MyFont);
  2536.   END;
  2537.   INC(fontHeight,spacing);               (* extra spacing *)
  2538.   fontBaseLine := rp.font.baseline;
  2539.  
  2540.   NumColumns := Screen.width DIV fontWidth;
  2541.   IF Scrollable THEN NumLines   := Screen.height DIV 2 DIV fontHeight;
  2542.                 ELSE NumLines   := Screen.height DIV fontHeight; END;
  2543.   PageHeight := fontHeight*NumLines;
  2544.  
  2545.   NuScreen.height := fontHeight*NumLines;
  2546.   NuScreen.width  := Screen.width;
  2547.  
  2548.  
  2549.   ClearBitMaps;
  2550.  
  2551.   IF Scrollable THEN
  2552.     Screen.height := NuScreen.height;
  2553.     I.MakeScreen(Screen);
  2554.     I.RethinkDisplay;
  2555.   END;
  2556.  
  2557.  
  2558. (*------  Open Window:  ------*)
  2559.  
  2560.   NuWindow.flags  := LONGSET{I.rmbTrap,I.activate,I.borderless,I.noCareRefresh,I.simpleRefresh,I.backDrop};
  2561.   NuWindow.screen := Screen;
  2562.   NuWindow.type   := I.customScreen;
  2563.   NuWindow.topEdge:= 10;
  2564.   NuWindow.width  := Screen.width;
  2565.   NuWindow.height := Screen.height-10;
  2566.   NuWindow.idcmpFlags := MyIdcmp;
  2567.   Window := I.OpenWindow(NuWindow);
  2568.   IF Window=NIL THEN Request(LocStr(MSGCOW)^) END;
  2569.  
  2570.  
  2571. (*------  Get KeyMap:  ------*)
  2572.  
  2573.   IF e.OpenDevice("console.device",-1,SYS.ADR(wreq),LONGSET{})#0 THEN HALT(d.fail) END;
  2574.   console := wreq.device;
  2575.   con.base := console;
  2576. (*ievent.nextEvent := NIL;
  2577.   ievent.qualifier := {};
  2578.   ievent.eventAddress := NIL; *)
  2579.   ievent.class := ie.rawkey;
  2580.  
  2581.   FOR i := 0 TO 3FH DO
  2582.     ievent.code := i;
  2583.     SYS.SETREG(0,con.RawKeyConvert(SYS.ADR(ievent),KeyMap[i],10H,NIL));
  2584.   END;
  2585.  
  2586. (*------  Decrunch:  ------*)
  2587.  
  2588.   Decrunch;
  2589.  
  2590. (*------  Init 2nd Task:  ------*)
  2591.  
  2592.   ShowTask.spLower := SYS.ADR(ShowStack);
  2593.   ShowTask.spUpper := SYS.ADR(ShowStack[1000]);
  2594.   ShowTask.spReg   := ShowTask.spUpper;
  2595.   ShowTask.node.type := e.task;
  2596.   ShowTask.node.name := SYS.ADR("mm.show");
  2597.   ShowTask.node.pri  := Me.task.node.pri+1;
  2598.   (* $IF SmallData *)
  2599.   ShowTask.userData  := SYS.REG(13);           (* VarBase *)
  2600.   (* $END *)
  2601.  
  2602.   e.Forbid;
  2603.    e.AddTask(SYS.ADR(ShowTask),ShowProc,NIL);
  2604.    ShowTaskRunning := w;
  2605.    Window.userPort.sigTask := SYS.ADR(ShowTask);
  2606.   e.Permit;
  2607.  
  2608. (*------  Main Load / Display Loop:  ------*)
  2609.  
  2610.   LOOP
  2611.     fg := 1; bg := 0; oldfg := fg; oldbg := bg; style := SHORTSET{};
  2612.     RQLen := -1; RQPos := -1;
  2613.     AnzLines := 1;
  2614.     LastLine := FirstLine;
  2615.     BottomLine := FirstLine;
  2616.     TopLine    := FirstLine;
  2617.     TextLength := 0;
  2618.     FindLine   := NIL;
  2619.     FOR i := 0 TO 9 DO TextMarkers[i] := NIL END;
  2620.  
  2621.     MyLock := d.Lock(Name,d.sharedLock);
  2622.     IF MyLock=NIL THEN Request(LocStr(MSGCOF)^) END;
  2623.     IF ~ d.Examine(MyLock,FileInfo) THEN Request(LocStr(MSGCOF)^) END;
  2624.     FileLength := FileInfo.size;
  2625.  
  2626.     d.UnLock(MyLock); MyLock := NIL;
  2627.     IF FileLength=0 THEN Request(LocStr(MSGEMPTY)^) END;
  2628.  
  2629.     (*------  Start displaying & Loading:  ------*)
  2630.  
  2631.     NewDisp := w;
  2632.  
  2633.     e.Signal(SYS.ADR(ShowTask),mySig);
  2634.  
  2635.     REPEAT
  2636.       LoadLine := GetTextLine();
  2637.       IF LoadLine=NIL THEN
  2638.         d.OldClose(MyFile);
  2639.         MyFile := NIL;
  2640.       ELSE
  2641.         LoadLine.prev := LastLine;
  2642.         LastLine.next := LoadLine;
  2643.         LastLine := LoadLine;
  2644.       END;
  2645.       IF SignalNewData THEN e.Signal(SYS.ADR(ShowTask),mySig) END;
  2646.     UNTIL (MyFile=NIL) OR Done OR NewText;
  2647.     IF SignalAllRead THEN e.Signal(SYS.ADR(ShowTask),mySig) END;
  2648.     REPEAT
  2649.       SYS.SETREG(0,e.Wait(mySig));
  2650.       IF print THEN
  2651.         in := d.Open("NIL:",d.oldFile); out := d.Open("NIL:",d.newFile);
  2652.         SYS.SETREG(0,d.Execute(PStr,in,out));
  2653.         d.OldClose(in); in := NIL; d.OldClose(out); out := NIL; print := f;
  2654.       END;
  2655.       IF save THEN
  2656.         in := d.Open(Name,d.oldFile);
  2657.         IF in=NIL THEN I.DisplayBeep(NIL) ELSE
  2658.           ol.New(buffer,savesize);
  2659.           SYS.SETREG(0,d.Seek(in,savefrom,0));
  2660.           IF d.Read(in,buffer^,savesize)#savesize THEN
  2661.             I.DisplayBeep(NIL); d.OldClose(in); in := NIL;
  2662.           ELSE
  2663.             d.OldClose(in); in := NIL;
  2664.             out := d.Open(WriteName,d.newFile);
  2665.             IF out=NIL THEN I.DisplayBeep(NIL) ELSE
  2666.               IF d.Write(out,buffer^,savesize)#savesize THEN I.DisplayBeep(NIL) END;
  2667.               d.OldClose(out); out := NIL;
  2668.             END;
  2669.           END;
  2670.           DISPOSE(buffer);
  2671.         END;
  2672.         save := f;
  2673.       END;
  2674.       IF Done THEN EXIT END;
  2675.     UNTIL NewText;
  2676.     IF MyFile#NIL THEN d.OldClose(MyFile); MyFile := NIL END;
  2677.     IF Decrunched & d.DeleteFile(Name) THEN END;
  2678.     Decrunched := f;
  2679.     DisposeLines();
  2680.     FirstLine^.next := NIL; NewText := f;
  2681.     Name := OldName;
  2682.     REPEAT
  2683.       FileReq(Name);
  2684.       MyFile := d.Open(Name,d.oldFile);
  2685.     UNTIL MyFile#NIL;
  2686.     Decrunch;
  2687.   END;   (* LOOP *)
  2688.  
  2689. CLOSE
  2690.  
  2691.   IF win         #NIL THEN I.CloseWindow(win)                   END;
  2692.   IF ShowTaskRunning  THEN e.RemTask(SYS.ADR(ShowTask))         END;
  2693.   IF console     #NIL THEN e.CloseDevice(SYS.ADR(wreq))         END;
  2694.   IF Window      #NIL THEN I.CloseWindow(Window)                END;
  2695.   IF Screen      #NIL THEN I.OldCloseScreen(Screen)             END;
  2696.   IF MyFont      #NIL THEN g.CloseFont(MyFont)                  END;
  2697.   IF MyFile      #NIL THEN d.OldClose(MyFile)                   END;
  2698.   IF in          #NIL THEN d.OldClose(in)                       END;
  2699.   IF out         #NIL THEN d.OldClose(out)                      END;
  2700.   IF Decrunched       THEN SYS.SETREG(0,d.DeleteFile(Name))     END;
  2701.   IF MyLock      #NIL THEN d.UnLock(MyLock)                     END;
  2702.   IF xpk         #NIL THEN e.CloseLibrary(xpk)                  END;
  2703.   IF arp         #NIL THEN e.CloseLibrary(arp)                  END;
  2704.   IF asl         #NIL THEN e.CloseLibrary(asl)                  END;
  2705.   IF diskFontBase#NIL THEN e.CloseLibrary(diskFontBase)         END;
  2706.   IF iconBase    #NIL THEN e.CloseLibrary(iconBase)             END;
  2707.   IF rd          #NIL THEN d.FreeArgs(rd)                       END;
  2708.   IF mySigBit>=0      THEN e.FreeSignal(mySigBit)               END;
  2709.   IF catalog     #NIL THEN loc.CloseCatalog(catalog);           END;
  2710.   IF taskpri  #oldpri THEN oldpri := e.SetTaskPri(Me,oldpri)    END;
  2711.   OldDir := d.CurrentDir(OldDir);
  2712.  
  2713. END MuchMore.
  2714.  
  2715.